From 4e38df86a5ddba8e9a7ab0ced8bc9498714096cb Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 3 Jun 2025 00:34:19 +0200 Subject: [PATCH 1/3] feat(repo): add workflow for automatic release --- .github/workflows/release_github.yml | 51 ++++++++++++++++++++++++++++ .github/workflows/release_pub.yml | 36 ++++++++++++++++++++ melos.yaml | 12 +++---- 3 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release_github.yml create mode 100644 .github/workflows/release_pub.yml diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml new file mode 100644 index 000000000..6a6cf69b3 --- /dev/null +++ b/.github/workflows/release_github.yml @@ -0,0 +1,51 @@ +name: release_github + +on: + push: + branches: [master] + +jobs: + release: + # Only run this job for commits that indicate a release + if: startsWith(github.event.head_commit.message, 'chore(repo): release') + runs-on: ubuntu-latest + + steps: + - name: 📚 Checkout branch + uses: actions/checkout@v3 + + - name: đŸˇī¸ Extract Version Tag + id: extract_tag + shell: bash + run: | + set -euo pipefail + + commit_msg="${{ github.event.head_commit.message }}" + echo "đŸ“Ļ Commit message: $commit_msg" + + # Match vX.Y.Z or vX.Y.Z-suffix (case-insensitive) + version_regex='[vV][0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.\-]+)?' + + if [[ "$commit_msg" =~ $version_regex ]]; then + version="${BASH_REMATCH[0]}" + is_prerelease=$([[ $version == *-* ]] && echo true || echo false) + + echo "✅ Found version tag: $version" + echo "â„šī¸ Pre-release: $is_prerelease" + + echo "tag=$version" >> "$GITHUB_OUTPUT" + echo "prerelease=$is_prerelease" >> "$GITHUB_OUTPUT" + else + echo "::error ::❌ No SemVer tag found in commit message." + echo "::error ::Expected something like: 'chore(repo): release v1.2.3[-beta]'" + exit 1 + fi + + - name: 🚀 Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + make_latest: true + generate_release_notes: true + tag_name: ${{ steps.extract_tag.outputs.tag }} + prerelease: ${{ steps.extract_tag.outputs.prerelease }} + token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release_pub.yml b/.github/workflows/release_pub.yml new file mode 100644 index 000000000..1132a1098 --- /dev/null +++ b/.github/workflows/release_pub.yml @@ -0,0 +1,36 @@ +name: release_pub + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + release: + permissions: + id-token: write # Required for authentication using OIDC + runs-on: ubuntu-latest + steps: + - name: 📚 Checkout branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Set up the Dart SDK and provision the OIDC token used for publishing. + - name: đŸŽ¯ Setup Dart + uses: dart-lang/setup-dart@v1 + + - name: đŸĻ Install Flutter + uses: subosito/flutter-action@v2 + + - name: đŸ“Ļ Install Tools + run: flutter pub global activate melos + + - name: 🔧 Bootstrap Workspace + run: melos bootstrap --verbose + + - name: đŸŒĩ Dry Run + run: melos run lint:pub + + - name: 🚀 Release to pub.dev + run: melos run release:pub \ No newline at end of file diff --git a/melos.yaml b/melos.yaml index 6a1d189df..a4e864e86 100644 --- a/melos.yaml +++ b/melos.yaml @@ -149,12 +149,8 @@ scripts: - Note: you can also rely on your IDEs Dart Analysis / Issues window. lint:pub: - run: | - melos exec -c 5 --no-private --ignore="*example*" -- \ - flutter pub publish --dry-run - description: | - Run `pub publish --dry-run` in all packages. - - Note: you can also rely on your IDEs Dart Analysis / Issues window. + run: melos exec -c1 --no-published --no-private --order-dependents -- "flutter pub publish -n" + description: Dry run `pub publish` in all packages. generate:all: run: melos run generate:dart && melos run generate:flutter @@ -206,3 +202,7 @@ scripts: description: Removes all the ignored files from the coverage report. packageFilters: dirExists: coverage + + release:pub: + run: melos exec -c1 --no-published --no-private --order-dependents -- "flutter pub publish -f" + description: Publish all packages to pub.dev. \ No newline at end of file From e1d4ce575278a8f947562fd2a7ca0ced23a3e939 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 3 Jun 2025 00:44:00 +0200 Subject: [PATCH 2/3] chore: apply review suggestion --- .github/workflows/release_github.yml | 4 ++-- melos.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml index 6a6cf69b3..2d0371bfe 100644 --- a/.github/workflows/release_github.yml +++ b/.github/workflows/release_github.yml @@ -7,12 +7,12 @@ on: jobs: release: # Only run this job for commits that indicate a release - if: startsWith(github.event.head_commit.message, 'chore(repo): release') + if: {{ startsWith(github.event.head_commit.message, 'chore(repo): release') }} runs-on: ubuntu-latest steps: - name: 📚 Checkout branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: đŸˇī¸ Extract Version Tag id: extract_tag diff --git a/melos.yaml b/melos.yaml index a4e864e86..008a10471 100644 --- a/melos.yaml +++ b/melos.yaml @@ -149,7 +149,7 @@ scripts: - Note: you can also rely on your IDEs Dart Analysis / Issues window. lint:pub: - run: melos exec -c1 --no-published --no-private --order-dependents -- "flutter pub publish -n" + run: melos exec -c 1 --no-published --no-private --order-dependents -- "flutter pub publish -n" description: Dry run `pub publish` in all packages. generate:all: @@ -204,5 +204,5 @@ scripts: dirExists: coverage release:pub: - run: melos exec -c1 --no-published --no-private --order-dependents -- "flutter pub publish -f" + run: melos exec -c 1 --no-published --no-private --order-dependents -- "flutter pub publish -f" description: Publish all packages to pub.dev. \ No newline at end of file From 8f6073048f3a3b5f823ecf2364532176ed4d2196 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 3 Jun 2025 12:13:22 +0200 Subject: [PATCH 3/3] chore: finalize worfklow --- .github/workflows/release_github.yml | 11 ++++++++--- .github/workflows/release_pub.yml | 5 ++++- melos.yaml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml index 2d0371bfe..bcc905c95 100644 --- a/.github/workflows/release_github.yml +++ b/.github/workflows/release_github.yml @@ -4,15 +4,21 @@ on: push: branches: [master] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: release: # Only run this job for commits that indicate a release - if: {{ startsWith(github.event.head_commit.message, 'chore(repo): release') }} + if: "${{ startsWith(github.event.head_commit.message, 'chore(repo): release') }}" runs-on: ubuntu-latest steps: - name: 📚 Checkout branch uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: đŸˇī¸ Extract Version Tag id: extract_tag @@ -44,8 +50,7 @@ jobs: - name: 🚀 Create GitHub Release uses: softprops/action-gh-release@v1 with: - make_latest: true generate_release_notes: true tag_name: ${{ steps.extract_tag.outputs.tag }} prerelease: ${{ steps.extract_tag.outputs.prerelease }} - token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }} \ No newline at end of file + token: ${{ secrets.BOT_GITHUB_API_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release_pub.yml b/.github/workflows/release_pub.yml index 1132a1098..c99f9a8f4 100644 --- a/.github/workflows/release_pub.yml +++ b/.github/workflows/release_pub.yml @@ -3,7 +3,10 @@ name: release_pub on: release: types: [published] - workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: release: diff --git a/melos.yaml b/melos.yaml index 008a10471..103b82f96 100644 --- a/melos.yaml +++ b/melos.yaml @@ -205,4 +205,4 @@ scripts: release:pub: run: melos exec -c 1 --no-published --no-private --order-dependents -- "flutter pub publish -f" - description: Publish all packages to pub.dev. \ No newline at end of file + description: Publish all packages to pub.dev.