Deploy flutter web application for review #240
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy flutter web application for review | |
on: | |
workflow_run: | |
workflows: ["PR review"] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: 'Download artifact' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr.zip`, Buffer.from(download.data)); | |
await github.rest.actions.deleteArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
}); | |
- name: 'Unzip artifact' | |
run: unzip pr.zip | |
- name: 'Set environment variable' | |
run: | | |
echo "PR_NUMBER=$(cat pr/number)" >> $GITHUB_ENV | |
- uses: FirebaseExtended/action-hosting-deploy@v0 | |
id: hosting | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_DEV }}" | |
expires: 7d | |
projectId: flutterkakgi-2023-conf-app-dev | |
# set channel id with pr_number and pr_head_sha | |
channelId: 'pr-${{ env.PR_NUMBER }}' | |
- name: 'Comment on PR' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const issue_number = Number(fs.readFileSync('./pr/number')); | |
const {data: comments} = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
}); | |
const bot_comment = comments.find(comment => comment.user.id === 41898282); | |
if (bot_comment) { | |
await github.rest.issues.deleteComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
comment_id: bot_comment.id, | |
}); | |
} | |
const comment_body = `Commented by GitHub Bot\n\nPR: #${issue_number}\n[preview link](${{ steps.hosting.outputs.details_url }})`; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: comment_body | |
}); |