|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + |
| 5 | +jobs: |
| 6 | + release: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + outputs: |
| 9 | + version: ${{ steps.create-github-release.outputs.version }} |
| 10 | + steps: |
| 11 | + - run: | |
| 12 | + if [[ $GITHUB_REF_NAME != release/* ]]; then |
| 13 | + echo this workflow should only be run against release branches |
| 14 | + exit 1 |
| 15 | + fi |
| 16 | +
|
| 17 | + - uses: actions/checkout@v3 |
| 18 | + |
| 19 | + - uses: actions/setup-java@v3 |
| 20 | + with: |
| 21 | + distribution: temurin |
| 22 | + java-version: 17 |
| 23 | + |
| 24 | + - name: Build and publish artifacts |
| 25 | + uses: gradle/gradle-build-action@v2 |
| 26 | + with: |
| 27 | + # TODO(jack-berg): add following arguments when confident in release process: closeAndReleaseSonatypeStagingRepository |
| 28 | + arguments: assemble publishToSonatype |
| 29 | + env: |
| 30 | + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} |
| 31 | + SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }} |
| 32 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 33 | + GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} |
| 34 | + |
| 35 | + - name: Set environment variables |
| 36 | + run: | |
| 37 | + version=$(.github/scripts/get-version.sh) |
| 38 | + if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then |
| 39 | + major="${BASH_REMATCH[1]}" |
| 40 | + minor="${BASH_REMATCH[2]}" |
| 41 | + patch="${BASH_REMATCH[3]}" |
| 42 | + else |
| 43 | + echo "unexpected version: $version" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + if [[ $patch == 0 ]]; then |
| 47 | + if [[ $minor == 0 ]]; then |
| 48 | + prior_major=$((major - 1)) |
| 49 | + prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1) |
| 50 | + prior_version="$prior_major.$prior_minor" |
| 51 | + else |
| 52 | + prior_version="$major.$((minor - 1)).0" |
| 53 | + fi |
| 54 | + else |
| 55 | + prior_version="$major.$minor.$((patch - 1))" |
| 56 | + fi |
| 57 | + echo "VERSION=$version" >> $GITHUB_ENV |
| 58 | + echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + # check out main branch to verify there won't be problems with merging the change log |
| 61 | + # at the end of this workflow |
| 62 | + - uses: actions/checkout@v3 |
| 63 | + with: |
| 64 | + ref: main |
| 65 | + |
| 66 | + - name: Check that change log update was merged to main |
| 67 | + run: | |
| 68 | + if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then |
| 69 | + echo the pull request generated by prepare-release-branch.yml needs to be merged first |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + # back to the release branch |
| 74 | + - uses: actions/checkout@v3 |
| 75 | + with: |
| 76 | + # tags are needed for the generate-release-contributors.sh script |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Generate release notes |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + # CHANGELOG_SECTION.md is also used at the end of the release workflow |
| 84 | + # for copying the change log updates to main |
| 85 | + sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \ |
| 86 | + > /tmp/CHANGELOG_SECTION.md |
| 87 | +
|
| 88 | + # the complex perl regex is needed because markdown docs render newlines as soft wraps |
| 89 | + # while release notes render them as line breaks |
| 90 | + perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \ |
| 91 | + >> /tmp/release-notes.txt |
| 92 | +
|
| 93 | + # conditional block not indented because of the heredoc |
| 94 | + cat >> /tmp/release-notes.txt << EOF |
| 95 | +
|
| 96 | + ### 🙇 Thank you |
| 97 | + This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests: |
| 98 | +
|
| 99 | + EOF |
| 100 | +
|
| 101 | + .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt |
| 102 | +
|
| 103 | + - id: create-github-release |
| 104 | + name: Create GitHub release |
| 105 | + env: |
| 106 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + run: | |
| 108 | + gh release create --target $GITHUB_REF_NAME \ |
| 109 | + --title "Version $VERSION" \ |
| 110 | + --notes-file /tmp/release-notes.txt \ |
| 111 | + --discussion-category announcements \ |
| 112 | + v$VERSION |
| 113 | +
|
| 114 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
0 commit comments