diff --git a/.github/workflows/preview_deploy.yml b/.github/workflows/preview_deploy.yml new file mode 100644 index 0000000..d27f677 --- /dev/null +++ b/.github/workflows/preview_deploy.yml @@ -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/github-script@v3.1.0 + 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 }}' + }); \ No newline at end of file diff --git a/.github/workflows/preview_generate.yml b/.github/workflows/preview_generate.yml new file mode 100644 index 0000000..92c21fb --- /dev/null +++ b/.github/workflows/preview_generate.yml @@ -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/setup-go@v2.1.3 + - 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/