Skip to content

Commit 5c5897f

Browse files
authored
Merge pull request #872 from graphql-java-kickstart/build/release-automation
Take the release version as a workflow input and run the checks on the bump PR
2 parents 7f7475c + 1f4c025 commit 5c5897f

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎.github/workflows/pull-request.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Pull request
22
on:
33
pull_request:
44
types: [ opened, reopened, synchronize ]
5+
workflow_dispatch:
56
jobs:
67
build:
78
runs-on: ubuntu-latest

‎.github/workflows/release.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Release
2-
on: [ workflow_dispatch ]
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: Version to release, e.g. 14.3.0
7+
required: true
38
permissions:
49
contents: read
510
jobs:
@@ -20,6 +25,7 @@ jobs:
2025
runs-on: ubuntu-latest
2126
needs: build
2227
permissions:
28+
actions: write
2329
contents: write
2430
pull-requests: write
2531
steps:
@@ -43,6 +49,7 @@ jobs:
4349
- name: Publish release
4450
run: bash github-build.sh
4551
env:
52+
RELEASE_VERSION: ${{ inputs.version }}
4653
MAVEN_USERNAME: ${{ secrets.OSS_USER_TOKEN_KEY }}
4754
MAVEN_PASSWORD: ${{ secrets.OSS_USER_TOKEN_PASS }}
4855
GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }}
@@ -54,3 +61,8 @@ jobs:
5461
title: Version Release
5562
body: |
5663
Bumping project version after release.
64+
- name: Run the pull request checks
65+
# Pull requests opened with GITHUB_TOKEN don't trigger workflows, but a workflow_dispatch sent with it does
66+
run: gh workflow run pull-request.yml --ref version-release
67+
env:
68+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎github-build.sh‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ requireSnapshot() {
1313
fi
1414
}
1515

16-
removeSnapshots() {
17-
sed -i 's/-SNAPSHOT//' pom.xml
16+
setReleaseVersion() {
17+
if [[ ! ${RELEASE_VERSION} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
18+
echo "Release version must look like 14.3.0: '${RELEASE_VERSION}'"
19+
exit 1
20+
fi
21+
sed -i "0,/<version>.*<\/version>/s//<version>${RELEASE_VERSION}<\/version>/" pom.xml
22+
local PREVIOUS_VERSION=${PREVIOUS_TAG#v}
23+
sed -i -e "s/graphql-java-tools:${PREVIOUS_VERSION}'/graphql-java-tools:${RELEASE_VERSION}'/" \
24+
-e "s/<version>${PREVIOUS_VERSION}<\/version>/<version>${RELEASE_VERSION}<\/version>/" README.md
25+
grep -q "<version>${RELEASE_VERSION}</version>" README.md || echo "::warning::README.md still shows another version, update it manually"
1826
}
1927

2028
commitRelease() {
@@ -27,7 +35,6 @@ publishTag() {
2735
local APP_VERSION=$(getVersion)
2836
git push origin "v${APP_VERSION}"
2937
# Release tags aren't on master's first-parent history, so GitHub can't find the previous one on its own
30-
local PREVIOUS_TAG=$(gh release view --json tagName --jq .tagName)
3138
gh release create "v${APP_VERSION}" --verify-tag --draft --generate-notes --notes-start-tag "${PREVIOUS_TAG}" --title "v${APP_VERSION}" \
3239
|| echo "::warning::Draft release for v${APP_VERSION} was not created, create it manually"
3340
}
@@ -61,9 +68,10 @@ git config --global user.email "actions@github.com"
6168
git config --global user.name "GitHub Actions"
6269

6370
requireSnapshot
71+
PREVIOUS_TAG=$(gh release view --json tagName --jq .tagName)
6472

6573
echo "Deploying release to Maven Central"
66-
removeSnapshots
74+
setReleaseVersion
6775

6876
mvn --batch-mode -Prelease deploy
6977

0 commit comments

Comments
 (0)