diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 7ceaf9fe..3d0bdc21 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,6 +2,7 @@ name: Pull request on: pull_request: types: [ opened, reopened, synchronize ] + workflow_dispatch: jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7010a978..e40d5577 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,10 @@ name: Release -on: [ workflow_dispatch ] +on: + workflow_dispatch: + inputs: + version: + description: Version to release, e.g. 14.3.0 + required: true permissions: contents: read jobs: @@ -20,6 +25,7 @@ jobs: runs-on: ubuntu-latest needs: build permissions: + actions: write contents: write pull-requests: write steps: @@ -43,6 +49,7 @@ jobs: - name: Publish release run: bash github-build.sh env: + RELEASE_VERSION: ${{ inputs.version }} MAVEN_USERNAME: ${{ secrets.OSS_USER_TOKEN_KEY }} MAVEN_PASSWORD: ${{ secrets.OSS_USER_TOKEN_PASS }} GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }} @@ -54,3 +61,8 @@ jobs: title: Version Release body: | Bumping project version after release. + - name: Run the pull request checks + # Pull requests opened with GITHUB_TOKEN don't trigger workflows, but a workflow_dispatch sent with it does + run: gh workflow run pull-request.yml --ref version-release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/github-build.sh b/github-build.sh index cbb928f3..7e16f617 100644 --- a/github-build.sh +++ b/github-build.sh @@ -13,8 +13,16 @@ requireSnapshot() { fi } -removeSnapshots() { - sed -i 's/-SNAPSHOT//' pom.xml +setReleaseVersion() { + if [[ ! ${RELEASE_VERSION} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Release version must look like 14.3.0: '${RELEASE_VERSION}'" + exit 1 + fi + sed -i "0,/.*<\/version>/s//${RELEASE_VERSION}<\/version>/" pom.xml + local PREVIOUS_VERSION=${PREVIOUS_TAG#v} + sed -i -e "s/graphql-java-tools:${PREVIOUS_VERSION}'/graphql-java-tools:${RELEASE_VERSION}'/" \ + -e "s/${PREVIOUS_VERSION}<\/version>/${RELEASE_VERSION}<\/version>/" README.md + grep -q "${RELEASE_VERSION}" README.md || echo "::warning::README.md still shows another version, update it manually" } commitRelease() { @@ -27,7 +35,6 @@ publishTag() { local APP_VERSION=$(getVersion) git push origin "v${APP_VERSION}" # Release tags aren't on master's first-parent history, so GitHub can't find the previous one on its own - local PREVIOUS_TAG=$(gh release view --json tagName --jq .tagName) gh release create "v${APP_VERSION}" --verify-tag --draft --generate-notes --notes-start-tag "${PREVIOUS_TAG}" --title "v${APP_VERSION}" \ || echo "::warning::Draft release for v${APP_VERSION} was not created, create it manually" } @@ -61,9 +68,10 @@ git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions" requireSnapshot +PREVIOUS_TAG=$(gh release view --json tagName --jq .tagName) echo "Deploying release to Maven Central" -removeSnapshots +setReleaseVersion mvn --batch-mode -Prelease deploy