|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: 'Type of release' |
| 8 | + required: true |
| 9 | + default: 'patch' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + release_name: |
| 16 | + description: 'Optional release name (e.g., "Bonobus alerts")' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + |
| 20 | +jobs: |
| 21 | + release: |
| 22 | + name: Create Release |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + |
| 27 | + steps: |
| 28 | + # 1. Setup |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Configure Git |
| 36 | + run: | |
| 37 | + git config user.name "github-actions[bot]" |
| 38 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 39 | +
|
| 40 | + # 2. Read current version |
| 41 | + - name: Read current version |
| 42 | + id: current_version |
| 43 | + run: | |
| 44 | + source version.properties |
| 45 | + echo "major=$major" >> $GITHUB_OUTPUT |
| 46 | + echo "minor=$minor" >> $GITHUB_OUTPUT |
| 47 | + echo "patch=$patch" >> $GITHUB_OUTPUT |
| 48 | + echo "snapshot=$snapshot" >> $GITHUB_OUTPUT |
| 49 | + echo "current=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + # 3. Validate current state |
| 52 | + - name: Validate snapshot state |
| 53 | + run: | |
| 54 | + if [ "${{ steps.current_version.outputs.snapshot }}" != "true" ]; then |
| 55 | + echo "Error: Cannot release from non-snapshot version" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + # 4. Prepare release version (remove snapshot) |
| 60 | + - name: Prepare release version |
| 61 | + id: release_version |
| 62 | + run: | |
| 63 | + ./scripts/prepare-release.sh ${{ github.event.inputs.release_type }} |
| 64 | + source version.properties |
| 65 | + echo "version=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + # 5. Commit release version |
| 68 | + - name: Commit release version |
| 69 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 70 | + with: |
| 71 | + commit_message: "chore: release v${{ steps.release_version.outputs.version }}" |
| 72 | + file_pattern: version.properties |
| 73 | + |
| 74 | + # 6. Create and push tag |
| 75 | + - name: Create release tag |
| 76 | + run: | |
| 77 | + git tag "v${{ steps.release_version.outputs.version }}" |
| 78 | + git push origin "v${{ steps.release_version.outputs.version }}" |
| 79 | +
|
| 80 | + # 7. Prepare next development version |
| 81 | + - name: Prepare next development version |
| 82 | + id: next_version |
| 83 | + run: | |
| 84 | + ./scripts/prepare-next-dev.sh |
| 85 | + source version.properties |
| 86 | + echo "next_version=${major}.${minor}.${patch}-snapshot" >> $GITHUB_OUTPUT |
| 87 | +
|
| 88 | + # 8. Commit next development version |
| 89 | + - name: Commit next development version |
| 90 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 91 | + with: |
| 92 | + commit_message: "chore: prepare next development iteration ${{ steps.next_version.outputs.next_version }}" |
| 93 | + file_pattern: version.properties |
| 94 | + |
| 95 | + create-github-release: |
| 96 | + name: Create GitHub Release |
| 97 | + runs-on: ubuntu-latest |
| 98 | + needs: release |
| 99 | + permissions: |
| 100 | + contents: write |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout repository |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + fetch-depth: 0 |
| 107 | + |
| 108 | + - name: Get release version from tag |
| 109 | + id: release_info |
| 110 | + run: | |
| 111 | + # Get the tag that was just created by the release job |
| 112 | + LATEST_TAG=$(git tag --sort=-version:refname | head -1) |
| 113 | + echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 114 | + echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT |
| 115 | +
|
| 116 | + - name: Get previous tag for release notes |
| 117 | + id: prev-tag |
| 118 | + run: | |
| 119 | + git fetch --tags |
| 120 | + PREV_TAG=$(git tag --sort=-version:refname | grep -v "${{ steps.release_info.outputs.tag }}" | head -1) |
| 121 | + echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT |
| 122 | +
|
| 123 | + - name: Generate release notes |
| 124 | + id: release-notes |
| 125 | + run: | |
| 126 | + if [ -n "${{ steps.prev-tag.outputs.prev_tag }}" ]; then |
| 127 | + COMMITS=$(git log --pretty=format:"- %s (%h)" ${{ steps.prev-tag.outputs.prev_tag }}..${{ steps.release_info.outputs.tag }}) |
| 128 | + else |
| 129 | + COMMITS=$(git log --pretty=format:"- %s (%h)" --max-count=10) |
| 130 | + fi |
| 131 | + echo "commits<<EOF" >> $GITHUB_OUTPUT |
| 132 | + echo "$COMMITS" >> $GITHUB_OUTPUT |
| 133 | + echo "EOF" >> $GITHUB_OUTPUT |
| 134 | +
|
| 135 | + - name: Create GitHub Release |
| 136 | + uses: ncipollo/release-action@v1 |
| 137 | + with: |
| 138 | + tag: "${{ steps.release_info.outputs.tag }}" |
| 139 | + name: "${{ steps.release_info.outputs.tag }}${{ github.event.inputs.release_name && format(' - {0}', github.event.inputs.release_name) || '' }}" |
| 140 | + body: | |
| 141 | + ## Changes in this release: |
| 142 | +
|
| 143 | + ${{ steps.release-notes.outputs.commits }} |
| 144 | +
|
| 145 | + --- |
| 146 | + This release will be automatically deployed to Google Play Internal Track. |
| 147 | + draft: false |
| 148 | + prerelease: false |
| 149 | + |
0 commit comments