Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/preview_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy Preview
on:
workflow_run:
workflows: ["Generate Preview"]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchPrArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var matchPreviewArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "preview"
})[0];
var downloadPr = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchPrArtifact.id,
archive_format: 'zip',
});
var downloadPreview = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchPreviewArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadPr.data));
fs.writeFileSync('${{github.workspace}}/firebase-rules.zip', Buffer.from(downloadPreview.data));
- run: |
unzip pr.zip
echo "pr_number=$(cat NR)" >> $GITHUB_ENV
mkdir firebase-rules
unzip firebase-rules.zip -d firebase-rules
- name: Deploy preview
id: deploy_preview
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_FIR_CODELABS_89252 }}'
projectId: fir-codelabs-89252
entryPoint: firebase-rules
channelId: ${{ env.pr_number }}
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
- name: Write Comment
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ env.pr_number }},
body: 'View preview ${{ steps.deploy_preview.outputs.details_url }}'
});
29 changes: 29 additions & 0 deletions .github/workflows/preview_generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Generate Preview
on:
pull_request:
paths:
- 'steps/**'
jobs:
build_and_preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go environment
uses: actions/[email protected]
- name: Generate preview
working-directory: ./steps
run: |
go get github.com/googlecodelabs/tools/claat
$HOME/go/bin/claat export index.lab.md
- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v2
with:
name: preview
path: steps/firebase-rules/
- uses: actions/upload-artifact@v2
with:
name: pr
path: pr/