Skip to content

Commit

Permalink
ci: migrate to firebase runners (#261)
Browse files Browse the repository at this point in the history
# What ❔
Migrate firebase jobs on self-hosted runners. 

## Why ❔
For make contribution in frontend app from forks

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
  • Loading branch information
otani88 authored Jun 3, 2024
1 parent 146e2d9 commit 02e2224
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 40 deletions.
41 changes: 32 additions & 9 deletions .github/workflows/app-deploy-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: pr-${{ github.event.number }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -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: |
Expand Down Expand Up @@ -54,15 +60,32 @@ 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 --project staging-scan-v2 hosting:channel:list --json | jq --arg channel_name "${CHANNEL_NAME}" -r '.result.channels[]|select(.name|contains($channel_name)) | .url')
echo $CHANNEL_URL
if [ -z "$CHANNEL_URL" ]; then
echo "New channel"
firebase --project staging-scan-v2 hosting:channel:create $CHANNEL_NAME
CHANNEL_URL=$(firebase --project staging-scan-v2 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 --project staging-scan-v2 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
Expand Down
41 changes: 29 additions & 12 deletions .github/workflows/app-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 --project scan-v2 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 --project scan-v2 hosting:channel:create $CHANNEL_NAME
CHANNEL_URL=$(firebase --project scan-v2 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 --project scan-v2 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
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/app-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Deploy App to Production
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
runs-on: matterlabs-firebase-deployer
permissions:
contents: read
steps:
Expand All @@ -19,6 +19,14 @@ jobs:
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:
Expand Down Expand Up @@ -48,11 +56,6 @@ jobs:
unzip storybook-static.zip -d packages/app
- name: Deploy
id: deploy
uses: matter-labs/action-hosting-deploy@main
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCAN_V2 }}'
projectId: scan-v2
channelID: live
entryPoint: ./packages/app
working-directory: ./packages/app
run: |
firebase --project scan-v2 deploy
24 changes: 14 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,25 @@ jobs:

deployFrontendToStaging:
name: Deploy Block Explorer frontend to staging
runs-on: ubuntu-latest
runs-on: matterlabs-firebase-deployer
permissions:
contents: read
needs: createReleaseVersion
if: ${{ github.ref == 'refs/heads/main' && needs.createReleaseVersion.outputs.releaseVersion != '' }}
steps:
- name: Checkout
uses: actions/checkout@v3
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:
Expand Down Expand Up @@ -181,11 +189,7 @@ jobs:
unzip storybook-static.zip -d packages/app
- name: Deploy
uses: matter-labs/action-hosting-deploy@main
id: deploy
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING_SCAN_V2 }}"
projectId: staging-scan-v2
channelID: live
entryPoint: ./packages/app
working-directory: ./packages/app
run: |
firebase --project staging-scan-v2 deploy

0 comments on commit 02e2224

Please sign in to comment.