diff --git a/.github/workflows/app-deploy-feature-branch.yml b/.github/workflows/app-deploy-feature-branch.yml index e7bc4fca0..8d71161f7 100644 --- a/.github/workflows/app-deploy-feature-branch.yml +++ b/.github/workflows/app-deploy-feature-branch.yml @@ -4,7 +4,7 @@ on: pull_request jobs: build: name: Build and Test App - runs-on: ubuntu-latest + runs-on: matterlabs-firebase-deployer permissions: contents: read pull-requests: write @@ -13,7 +13,9 @@ jobs: run: working-directory: ./packages/app outputs: - dappUrl: ${{ steps.deploy.outputs.details_url }} + dappUrl: ${{ steps.check_channel.outputs.channel_url }} + env: + CHANNEL_NAME: ${{ github.head_ref }} steps: - name: Checkout uses: actions/checkout@v3 @@ -26,6 +28,10 @@ jobs: node-version: '18' cache: 'npm' + - name: Install Firebase CLI and auth + run: | + npm install -g firebase-tools + - name: Install dependencies working-directory: ./ run: | @@ -54,15 +60,30 @@ jobs: run: | echo "window[\"##runtimeConfig\"] = { appEnvironment: \"staging\" };" > dist/config.js + - name: Check if Firebase Hosting channel exists + working-directory: ./packages/app + id: check_channel + run: | + CHANNEL_URL=$(firebase hosting:channel:list --json | jq --arg channel_name "${CHANNEL_NAME}" -r '.result.channels[]|select(.name|contains($channel_name)) | .url') + if [ -z "$CHANNEL_URL" ]; then + echo "New channel" + firebase hosting:channel:create $CHANNEL_NAME + CHANNEL_URL=$(firebase hosting:channel:list --json | jq --arg channel_name "${CHANNEL_NAME}" -r '.result.channels[]|select(.name|contains($channel_name)) | .url') + fi + echo "channel_url=${CHANNEL_URL}" >> $GITHUB_OUTPUT + - name: Deploy - uses: matter-labs/action-hosting-deploy@main - id: deploy + working-directory: ./packages/app + run: | + firebase hosting:channel:deploy ${{ env.CHANNEL_NAME }} + + - name: Publish preview url + uses: thollander/actions-comment-pull-request@v2 with: - repoToken: "${{ github.token }}" - firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING_SCAN_V2 }}" - expires: 7d - projectId: staging-scan-v2 - entryPoint: ./packages/app + comment_tag: preview_url + message: | + Visit the preview URL for this PR: + ${{ steps.check_channel.outputs.channel_url }} mainnet: needs: build diff --git a/.github/workflows/app-deploy-preview.yml b/.github/workflows/app-deploy-preview.yml index b2208e066..6077b6878 100644 --- a/.github/workflows/app-deploy-preview.yml +++ b/.github/workflows/app-deploy-preview.yml @@ -10,17 +10,28 @@ name: Deploy App to Preview jobs: deploy: name: Deploy - runs-on: ubuntu-latest + runs-on: matterlabs-firebase-deployer permissions: contents: read outputs: - dappUrl: ${{ steps.deploy.outputs.details_url }} + dappUrl: ${{ steps.check_channel.outputs.channel_url }} + env: + CHANNEL_NAME: ${{ github.event.inputs.version }} steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install Firebase CLI and auth + run: | + npm install -g firebase-tools + - name: Download Dist package uses: dsaltares/fetch-gh-release-asset@master with: @@ -45,21 +56,27 @@ jobs: run: | unzip storybook-static.zip -d packages/app + - name: Check if Firebase Hosting channel exists + working-directory: ./packages/app + id: check_channel + run: | + CHANNEL_URL=$(firebase hosting:channel:list --json | jq --arg channel_name "${CHANNEL_NAME}" -r '.result.channels[]|select(.name|contains($channel_name)) | .url') + if [ -z "$CHANNEL_URL" ]; then + echo "New channel" + firebase hosting:channel:create $CHANNEL_NAME + CHANNEL_URL=$(firebase hosting:channel:list --json | jq --arg channel_name "${CHANNEL_NAME}" -r '.result.channels[]|select(.name|contains($channel_name)) | .url') + fi + echo "channel_url=${CHANNEL_URL}" >> $GITHUB_OUTPUT + - name: Deploy - id: deploy - uses: matter-labs/action-hosting-deploy@main - with: - repoToken: "${{ secrets.GITHUB_TOKEN }}" - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCAN_V2 }}' - expires: 7d - projectId: scan-v2 - channelID: ${{ github.event.inputs.version }} - entryPoint: ./packages/app + working-directory: ./packages/app + run: | + firebase hosting:channel:deploy ${{ env.CHANNEL_NAME }} - name: Output version url on success run: | run: | - echo "Block explorer app has been deployed to: ${{ steps.deploy.outputs.details_url }}" + echo "Block explorer app has been deployed to: ${{ steps.check_channel.outputs.channel_url }} mainnet: needs: deploy diff --git a/.github/workflows/app-deploy-prod.yml b/.github/workflows/app-deploy-prod.yml index 6554543c8..88d754262 100644 --- a/.github/workflows/app-deploy-prod.yml +++ b/.github/workflows/app-deploy-prod.yml @@ -58,4 +58,4 @@ jobs: - name: Deploy working-directory: ./packages/app run: | - firebase hosting:channel:deploy live + firebase deploy diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3ae47d09..4fd51fe33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -151,12 +151,15 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - uses: actions/setup-node@v4 with: node-version: 18 + - name: Install Firebase CLI and auth run: | npm install -g firebase-tools + - name: Download Dist package uses: dsaltares/fetch-gh-release-asset@master with: @@ -188,5 +191,5 @@ jobs: - name: Deploy working-directory: ./packages/app run: | - firebase hosting:channel:deploy live + firebase deploy