From 3a960a1f776f3c372d3a6fdb6c2047ab4cf3c02f Mon Sep 17 00:00:00 2001 From: Manindra de Me Date: Tue, 3 Dec 2024 13:57:36 +1100 Subject: [PATCH] split into two workflows --- .github/workflows/publish.yml | 12 +++++++++++ .github/workflows/update_metadata.yml | 31 ++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fb76fca --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,12 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' + +jobs: + publish: + permissions: + id-token: write # Required for authentication using OIDC + uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 \ No newline at end of file diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 1e706e3..48b4d93 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -1,4 +1,5 @@ -name: Update Metadata and Publish +name: Update Metadata + on: schedule: # At 12:00 AM, on day 1 of each month @@ -6,10 +7,13 @@ on: workflow_dispatch: jobs: - update-and-publish: + update: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for git describe + - uses: dart-lang/setup-dart@v1 - name: Install dependencies @@ -26,7 +30,7 @@ jobs: dart pub get dart resources/generate_files.dart && dart format lib/src && dart fix --apply - - name: Update Version + - name: Update Version and Create Tag run: | # Read the current version from pubspec.yaml CURRENT_VERSION=$(grep 'version:' pubspec.yaml | sed 's/version: //') @@ -34,21 +38,14 @@ jobs: NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') # Update pubspec.yaml with new version sed -i "s/version: $CURRENT_VERSION/version: $NEW_VERSION/" pubspec.yaml - - - name: Commit and Push Updated Files - run: | + + # Commit and push changes git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" git add . - git commit -m "Update Metadata and bump version" || echo "Nothing to commit!" + git commit -m "Update Metadata and bump version to $NEW_VERSION" || exit 0 git push - - - name: Publish to pub.dev - env: - PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }} - run: | - # Create credentials file - mkdir -p ~/.pub-cache - echo "$PUB_CREDENTIALS" > ~/.pub-cache/credentials.json - # Publish package - dart pub publish --force \ No newline at end of file + + # Create and push tag + git tag "v$NEW_VERSION" + git push origin "v$NEW_VERSION" \ No newline at end of file