Create Release #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: 'Type of release' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| release_name: | |
| description: 'Optional release name (e.g., "Bonobus alerts")' | |
| required: false | |
| type: string | |
| jobs: | |
| release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| # 1. Setup | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # 2. Read current version | |
| - name: Read current version | |
| id: current_version | |
| run: | | |
| source version.properties | |
| echo "major=$major" >> $GITHUB_OUTPUT | |
| echo "minor=$minor" >> $GITHUB_OUTPUT | |
| echo "patch=$patch" >> $GITHUB_OUTPUT | |
| echo "snapshot=$snapshot" >> $GITHUB_OUTPUT | |
| echo "current=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT | |
| # 3. Validate current state | |
| - name: Validate snapshot state | |
| run: | | |
| if [ "${{ steps.current_version.outputs.snapshot }}" != "true" ]; then | |
| echo "Error: Cannot release from non-snapshot version" | |
| exit 1 | |
| fi | |
| # 4. Prepare release version (remove snapshot) | |
| - name: Prepare release version | |
| id: release_version | |
| run: | | |
| ./scripts/prepare-release.sh ${{ github.event.inputs.release_type }} | |
| source version.properties | |
| echo "version=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT | |
| # 5. Commit release version | |
| - name: Commit release version | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore: release v${{ steps.release_version.outputs.version }}" | |
| file_pattern: version.properties | |
| # 6. Create and push tag | |
| - name: Create release tag | |
| run: | | |
| git tag "v${{ steps.release_version.outputs.version }}" | |
| git push origin "v${{ steps.release_version.outputs.version }}" | |
| # 7. Prepare next development version | |
| - name: Prepare next development version | |
| id: next_version | |
| run: | | |
| ./scripts/prepare-next-dev.sh | |
| source version.properties | |
| echo "next_version=${major}.${minor}.${patch}-snapshot" >> $GITHUB_OUTPUT | |
| # 8. Commit next development version | |
| - name: Commit next development version | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore: prepare next development iteration ${{ steps.next_version.outputs.next_version }}" | |
| file_pattern: version.properties | |
| create-github-release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: release | |
| permissions: | |
| contents: write | |
| outputs: | |
| tag: ${{ steps.release_info.outputs.tag }} | |
| release_name: ${{ steps.release_info.outputs.tag }}${{ github.event.inputs.release_name && format(' - {0}', github.event.inputs.release_name) || '' }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get release version from tag | |
| id: release_info | |
| run: | | |
| # Get the tag that was just created by the release job | |
| LATEST_TAG=$(git tag --sort=-version:refname | head -1) | |
| echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT | |
| - name: Get previous tag for release notes | |
| id: prev-tag | |
| run: | | |
| git fetch --tags | |
| PREV_TAG=$(git tag --sort=-version:refname | grep -v "${{ steps.release_info.outputs.tag }}" | head -1) | |
| echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| - name: Generate release notes | |
| id: release-notes | |
| run: | | |
| if [ -n "${{ steps.prev-tag.outputs.prev_tag }}" ]; then | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" ${{ steps.prev-tag.outputs.prev_tag }}..${{ steps.release_info.outputs.tag }}) | |
| else | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --max-count=10) | |
| fi | |
| echo "commits<<EOF" >> $GITHUB_OUTPUT | |
| echo "$COMMITS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: "${{ steps.release_info.outputs.tag }}" | |
| name: "${{ steps.release_info.outputs.tag }}${{ github.event.inputs.release_name && format(' - {0}', github.event.inputs.release_name) || '' }}" | |
| body: | | |
| ## Changes in this release: | |
| ${{ steps.release-notes.outputs.commits }} | |
| --- | |
| This release will be automatically deployed to Google Play Internal Track. | |
| draft: false | |
| prerelease: false | |
| deploy-google-play: | |
| name: Deploy to Google Play | |
| runs-on: ubuntu-latest | |
| needs: create-github-release | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-github-release.outputs.tag }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Create secret.properties | |
| run: echo "MAPS_API_KEY=${{ secrets.MAPS_API_KEY }}" > secret.properties | |
| - name: Create google-services.json | |
| run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > app/google-services.json | |
| - name: Decode Keystore | |
| run: | | |
| mkdir -p certs | |
| echo "${{ secrets.RELEASE_KEYSTORE_BASE64 }}" | base64 -d > certs/release.keystore | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| gradle-version: wrapper | |
| cache-read-only: false | |
| - name: Build release AAB | |
| run: ./gradlew :app:bundleRelease | |
| env: | |
| KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
| KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| - name: Upload to Google Play Internal Track | |
| uses: r0adkll/upload-google-play@v1 | |
| with: | |
| serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }} | |
| packageName: com.sloy.sevibus | |
| releaseFiles: app/build/outputs/bundle/release/app-release.aab | |
| track: internal | |
| releaseName: "${{ needs.create-github-release.outputs.release_name }}" | |