From 26ec09eabf1acbc7a2d8594f633d8d5a51fe1ef0 Mon Sep 17 00:00:00 2001 From: Nico Vidoni <30844036+smallTrogdor@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:57:16 +0100 Subject: [PATCH] ci(release): use github app in releases and add pub dev automated publishing (#244) --- .github/workflows/github-release.yml | 19 ++++++++++++++++++- .github/workflows/make-release-pr.yml | 14 ++++++++------ .github/workflows/pubdev-release.yml | 24 ++++++++++++++++++++++++ RELEASE.md | 21 ++++++++++++++++++--- 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/pubdev-release.yml diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index 25e39dc..3e3b7ad 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -16,10 +16,21 @@ jobs: outputs: tag_name: ${{ steps.read-changelog.outputs.version }} + github-app-token: ${{ steps.app-token.outputs.token }} steps: + - name: Generate Token for sbb-app-bakery GH App + id: app-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.APPBAKERYGITHUBAPP_APPID }} + private-key: ${{ secrets.APPBAKERYGITHUBAPP_PRIVATEKEY }} + - name: Clone Repository uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + persist-credentials: false - name: Changelog Reader id: read-changelog @@ -27,6 +38,10 @@ jobs: - name: Create tag uses: actions4git/setup-git@v1.0.3 + with: + github-token: ${{ steps.app-token.outputs.token }} + user-name: sbb-app-bakery[bot] + user-email: 914587+sbb-app-bakery[bot]@users.noreply.github.com - run: git tag -a ${{ steps.read-changelog.outputs.version }} -m "Version Release ${{ steps.read-changelog.outputs.version }} on ${{ steps.read-changelog.outputs.date }}" - run: git push --follow-tags @@ -37,11 +52,13 @@ jobs: - name: Clone Repository uses: actions/checkout@v4 with: + token: ${{ needs.create-tag.outputs.github-app-token }} ref: refs/tags/${{ needs.create-tag.outputs.tag_name }} + persist-credentials: false - name: Create GitHub Releases based on changelog uses: taiki-e/create-gh-release-action@v1.8.2 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ needs.create-tag.outputs.github-app-token }} ref: refs/tags/${{ needs.create-tag.outputs.tag_name }} changelog: ./CHANGELOG.md diff --git a/.github/workflows/make-release-pr.yml b/.github/workflows/make-release-pr.yml index c7a3406..d311068 100644 --- a/.github/workflows/make-release-pr.yml +++ b/.github/workflows/make-release-pr.yml @@ -1,12 +1,12 @@ -name: Make Release PR. +name: Make Release PR -on: +on: workflow_dispatch: inputs: semantic-versioning: description: Whether to increase major, minor or patch. required: true - default: 'patch' + default: "patch" type: choice options: - patch @@ -27,11 +27,12 @@ jobs: with: app-id: ${{ vars.APPBAKERYGITHUBAPP_APPID }} private-key: ${{ secrets.APPBAKERYGITHUBAPP_PRIVATEKEY }} - + - name: Clone Repository uses: actions/checkout@v4 with: token: ${{ steps.app-token.outputs.token }} + persist-credentials: false - name: Update Changelog id: update-changelog @@ -40,7 +41,7 @@ jobs: command: bump version: ${{ inputs.semantic-versioning }} keep-unreleased-section: true - tag-prefix: '' + tag-prefix: "" - name: Update Pubspec version uses: Dbono-dev/yaml-action@v1.0.4 @@ -49,12 +50,13 @@ jobs: { "version": "${{ steps.update-changelog.outputs.version }}" } - commentOutDevDependencies: 'false' + commentOutDevDependencies: "false" - name: Create Pull Request uses: peter-evans/create-pull-request@v7.0.5 with: token: ${{ steps.app-token.outputs.token }} + committer: sbb-app-bakery[bot] <914587+sbb-app-bakery[bot]@users.noreply.github.com> commit-message: ${{ format('Prepare Release for version {0}', steps.update-changelog.outputs.version) }} branch: ${{ format('release/{0}', steps.update-changelog.outputs.version) }} title: ${{ format('Auto Release Pull Request {0}', steps.update-changelog.outputs.version) }} diff --git a/.github/workflows/pubdev-release.yml b/.github/workflows/pubdev-release.yml new file mode 100644 index 0000000..d841766 --- /dev/null +++ b/.github/workflows/pubdev-release.yml @@ -0,0 +1,24 @@ +name: Publish to pub.dev + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" # tag pattern on pub.dev: '{{version}}' + +# Publish using custom workflow +jobs: + publish: + permissions: + id-token: write # Required for authentication using OIDC + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + - run: flutter doctor -v + - run: flutter pub get + - run: dart run build_runner build --delete-conflicting-outputs + - run: flutter pub publish --force diff --git a/RELEASE.md b/RELEASE.md index 6575144..5bb86a6 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,8 +1,23 @@ ### Release -The maintainers of this library can create a release by triggering the `Design System Flutter Release` workflow with the _patch_, _minor_ or _major_ option. This does several things: +##### Release PR + +The maintainers of this library can create a release by triggering the `make-release-pr` +workflow with the _patch_, _minor_ or _major_ option. This does several things: 1. Update the `pubspec.yaml` to reflect the new version. 2. Update the `CHANGELOG.md` to reflect the new version. -3. Commit and tag these changes in a new commit by the `@github-action[bot]`. -4. Create a GitHub release with the notes from the top `CHANGELOG.md` section (from the `github-release.yml` workflow). \ No newline at end of file +3. Commit and tag these changes in a new commit by the `sbb-app-bakery[bot]`. +4. Create a pull request with these changes with the `autorelease` label. + +##### Github release + +Merging a pull request with the `autorelease` label will trigger the `github-release` workflow that does several things: + +1. Create a tag with the new version from the `CHANGELOG.md`. +2. Make a github release based on the `CHANGELOG.md` and the version of the tag. + +##### Pub Dev release + +The creation of a tag in the `github-release` workflow triggers the `pubdev-release` workflow. This workflow simply +pushes the latest version to pub dev.