diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index cbd9448..bcf5f60 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -1,4 +1,4 @@ -name: Update Manifest and Commit Changes +name: "Update Configuration and Build" on: workflow_dispatch: @@ -6,16 +6,16 @@ on: jobs: update-manifest: - name: "Update Manifest and Commit Changes" + name: "Update Configuration & Build" runs-on: ubuntu-latest permissions: write-all steps: - - name: Update Manifest and Commit Changes - uses: ubiquity-os/action-deploy-plugin@main + - uses: ubiquity-os/action-deploy-plugin@main with: treatAsEsm: false sourcemap: false pluginEntry: ${{ github.workspace }}/src/main.ts env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} diff --git a/.github/workflows/worker-deploy.yml b/.github/workflows/worker-deploy.yml index 6e7ece3..7a6c481 100644 --- a/.github/workflows/worker-deploy.yml +++ b/.github/workflows/worker-deploy.yml @@ -1,14 +1,23 @@ name: Deploy Worker on: - push: workflow_dispatch: + workflow_run: + workflows: ["Update Configuration and Build"] + types: + - completed + +env: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} jobs: deploy-to-cloudflare: runs-on: ubuntu-latest name: Automatic Cloudflare Deploy environment: ${{ github.ref == 'refs/heads/main' && 'main' || 'development' }} + permissions: + contents: write steps: - name: Setup Node @@ -16,9 +25,6 @@ jobs: with: node-version: "20.10.0" - - name: Enable corepack - run: corepack enable - - uses: actions/checkout@v4 - name: Setup Bun @@ -26,7 +32,7 @@ jobs: - name: Update wrangler.toml Name Field run: | - branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') + branch_name=$(echo '${{ github.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') # Extract base name from wrangler.toml base_name=$(grep '^name = ' wrangler.toml | sed 's/^name = "\(.*\)"$/\1/') # Concatenate branch name with base name @@ -57,6 +63,46 @@ jobs: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} KERNEL_PUBLIC_KEY: ${{ secrets.KERNEL_PUBLIC_KEY }} + - name: Update manifest.json worker url + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); + + manifest["homepage_url"] = "${{ steps.wrangler_deploy.outputs.deployment-url }}"; + + const updatedManifest = JSON.stringify(manifest, null, 2); + fs.writeFileSync(manifestPath, updatedManifest); + console.log('Updated manifest:', updatedManifest); + + - name: Get GitHub App token + if: env.APP_ID != '' && env.APP_PRIVATE_KEY != '' + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ env.APP_ID }} + private-key: ${{ env.APP_PRIVATE_KEY }} + + - name: Format manifest.json using Prettier + shell: bash + run: | + bun add -DE prettier + bun prettier --write . + + - name: Commit file + uses: swinton/commit@v2.x + env: + GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }} + with: + files: | + manifest.json + commit-message: "chore: [skip ci] update manifest.json url" + ref: ${{ github.ref }} + - name: Write Deployment URL to Summary run: | echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY