|
| 1 | +on: |
| 2 | + workflow_run: |
| 3 | + |
| 4 | +jobs: |
| 5 | + test: |
| 6 | + runs-on: ubuntu-22.04 |
| 7 | + if: > |
| 8 | + (github.event.workflow_run.event == 'pull_request' || |
| 9 | + github.event.workflow_run.event == 'pull_request_target') && |
| 10 | + github.event.workflow_run.conclusion == 'success' |
| 11 | +
|
| 12 | + steps: |
| 13 | + - name: 'Download artifact' |
| 14 | + uses: actions/github-script@v3.1.0 |
| 15 | + with: |
| 16 | + script: | |
| 17 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 18 | + owner: context.repo.owner, |
| 19 | + repo: context.repo.repo, |
| 20 | + run_id: ${{github.event.workflow_run.id }}, |
| 21 | + }); |
| 22 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 23 | + return artifact.name == "doc-build-artifact" |
| 24 | + })[0]; |
| 25 | + var download = await github.actions.downloadArtifact({ |
| 26 | + owner: context.repo.owner, |
| 27 | + repo: context.repo.repo, |
| 28 | + artifact_id: matchArtifact.id, |
| 29 | + archive_format: 'zip', |
| 30 | + }); |
| 31 | + var fs = require('fs'); |
| 32 | + fs.writeFileSync('${{steps.setup-env.outputs.current_work_dir}}/doc-build-artifact.zip', Buffer.from(download.data)); |
| 33 | +
|
| 34 | + - run: | |
| 35 | + mkdir build_dir |
| 36 | + unzip doc-build-artifact.zip -d build_dir |
| 37 | +
|
| 38 | + - name: Get commit_sha & pr_number |
| 39 | + id: github-context |
| 40 | + run: | |
| 41 | + content_commit_sha=$(cat ./build_dir/commit_sha) |
| 42 | + if [[ $content_commit_sha =~ ^[0-9a-zA-Z]{40}$ ]]; then |
| 43 | + echo "commit_sha=$content_commit_sha" >> $GITHUB_OUTPUT |
| 44 | + rm -rf ./build_dir/commit_sha |
| 45 | + else |
| 46 | + echo "Encountered an invalid commit_sha" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + content_pr_number=$(cat ./build_dir/pr_number) |
| 51 | + if [[ $content_pr_number =~ ^[0-9]+$ ]]; then |
| 52 | + echo "pr_number=$content_pr_number" >> $GITHUB_OUTPUT |
| 53 | + rm -rf ./build_dir/pr_number |
| 54 | + else |
| 55 | + echo "Encountered an invalid pr_number" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + - run: | |
| 60 | + echo "hub_docs_url=pr_${{ steps.github-context.outputs.pr_number }}" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + - run: | |
| 63 | + cd build_dir |
| 64 | + doc-builder push --commit_msg "Updated with commit ${{ steps.github-context.outputs.commit_sha }} |
0 commit comments