From aaf1bb95bb7dcb0cc6a830af8f46ef3d1c74c2b0 Mon Sep 17 00:00:00 2001 From: JarvanMo Date: Tue, 5 Nov 2024 22:55:03 +0800 Subject: [PATCH] add automated publishing --- .github/actions/publish_flutter_package.yaml | 41 ++++++++++++++++++++ .github/workflows/publish.yml | 14 +++---- 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .github/actions/publish_flutter_package.yaml diff --git a/.github/actions/publish_flutter_package.yaml b/.github/actions/publish_flutter_package.yaml new file mode 100644 index 00000000..0726e249 --- /dev/null +++ b/.github/actions/publish_flutter_package.yaml @@ -0,0 +1,41 @@ +name: Publish Flutter package to pub.dev +description: Publish your Flutter package to pub.dev + +inputs: + working-directory: + description: directory with-in the repository where the package is located (if not in the repository root) + required: false + +runs: + using: "composite" + steps: + - name: 📚 Git Checkout + uses: actions/checkout@v4 + - name: 🐦 Setup Flutter + uses: subosito/flutter-action@v2 + + - name: 🪪 Get Id Token + uses: actions/github-script@v6 + with: + script: | + let pub_token = await core.getIDToken('https://pub.dev') + core.exportVariable('PUB_TOKEN', pub_token) + + - name: 📢 Authenticate + shell: ${{ inputs.shell }} + run: flutter pub pub token add https://pub.dev --env-var PUB_TOKEN + + - name: 📦 Install dependencies + shell: ${{ inputs.shell }} + run: flutter pub get + working-directory: ${{ inputs.working-directory }} + + - name: 🌵 Dry Run + shell: ${{ inputs.shell }} + run: flutter pub publish --dry-run + working-directory: ${{ inputs.working-directory }} + + - name: 📢 Publish + shell: ${{ inputs.shell }} + run: flutter pub publish -f + working-directory: ${{ inputs.working-directory }} \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index faf49cb6..b69901d6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,13 +7,13 @@ on: jobs: publish: + environment: 'pub.dev' + permissions: + id-token: write # Required for authentication using OIDC runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v3 - - name: Publish - uses: k-paxian/dart-package-publisher@master + - name: 📚 Git Checkout + uses: actions/checkout@v4 with: - credentialJson: ${{ secrets.CREDENTIAL_JSON }} - flutter: true - skipTests: true \ No newline at end of file + submodules: recursive + - uses: ./.github/actions/publish_flutter_package \ No newline at end of file