Update PR details #277
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: Update PR details | |
# read-write repo token | |
# access to secrets | |
on: | |
workflow_run: | |
workflows: ["Build and check Erlang/OTP"] | |
types: | |
- requested | |
- completed | |
# Limit concurrency so that we don't get any races between parallel actions | |
concurrency: pr-comment | |
jobs: | |
pr-number: | |
runs-on: ubuntu-20.04 | |
if: github.repository == 'erlang/otp' | |
outputs: | |
result: ${{ steps.pr-number.outputs.result }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Fetch PR number | |
id: pr-number | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
run: | | |
git clone https://github.com/talentdeficit/jsx | |
(cd jsx && rebar3 compile) | |
.github/scripts/get-pr-number.es erlang/otp \ | |
"${{ github.event.workflow_run.head_sha }}" | |
starting-tests: | |
runs-on: ubuntu-latest | |
needs: pr-number | |
if: github.event.action == 'requested' && needs.pr-number.outputs.result != '' | |
steps: | |
- uses: actions/checkout@v2 | |
## We create an initial comment with some useful help to the user | |
- uses: actions/[email protected] | |
with: | |
script: | | |
const script = require('./.github/scripts/pr-comment.js'); | |
return await script({github, context, state: 'starting', | |
pr_number: ${{ needs.pr-number.outputs.result }} }); | |
finished-tests: | |
runs-on: ubuntu-20.04 | |
needs: pr-number | |
## Limit concurrency so that only one job deploys to erlang.github.io | |
concurrency: erlang.github.io-deploy | |
if: >- | |
github.event.action == 'completed' && | |
needs.pr-number.outputs.result != '' && | |
github.event.workflow_run.conclusion != 'skipped' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Download and Extract Artifacts | |
id: extract | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
run: | | |
mkdir -p artifacts && cd artifacts | |
artifacts_url=${{ github.event.workflow_run.artifacts_url }} | |
gh api "$artifacts_url" --paginate -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact | |
do | |
IFS=$'\t' read name url <<< "$artifact" | |
if [ "$name" = "Unit Test Results" ] || [ "$name" = "Event File" ]; then | |
gh api $url > "$name.zip" | |
unzip -d "$name" "$name.zip" | |
fi | |
done | |
if [ -d "Unit Test Results" ]; then | |
echo "HAS_TEST_ARTIFACTS=true" >> $GITHUB_OUTPUT | |
else | |
echo "HAS_TEST_ARTIFACTS=false" >> $GITHUB_OUTPUT | |
fi | |
- uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.ERLANG_TOKEN }} | |
repository: 'erlang/erlang.github.io' | |
path: erlang.github.io | |
- name: Publish CT Test Results | |
uses: EnricoMi/publish-unit-test-result-action@v1 | |
if: steps.extract.outputs.HAS_TEST_ARTIFACTS == 'true' | |
with: | |
commit: ${{ github.event.workflow_run.head_sha }} | |
event_file: artifacts/Event File/event.json | |
event_name: ${{ github.event.workflow_run.event }} | |
check_name: "CT Test Results" | |
files: "artifacts/**/*.xml" | |
- name: Upload PR to github pages | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
run: | | |
git clone https://github.com/talentdeficit/jsx | |
(cd jsx && rebar3 compile) | |
mkdir -p "${GITHUB_WORKSPACE}/erlang.github.io/prs/" | |
.github/scripts/sync-github-prs.es erlang/otp \ | |
"${GITHUB_WORKSPACE}/erlang.github.io/prs/" \ | |
"${{ needs.pr-number.outputs.result }}" | |
- name: Deploy to github pages 🚀 | |
uses: JamesIves/[email protected] | |
with: | |
token: ${{ secrets.ERLANG_TOKEN }} | |
branch: master # The branch the action should deploy to. | |
folder: erlang.github.io # The folder the action should deploy. | |
repository-name: erlang/erlang.github.io | |
single-commit: true | |
## Append some usefull links and tips to the test results posted by | |
## Publish CT Test Results | |
- uses: actions/[email protected] | |
if: always() | |
with: | |
script: | | |
const script = require('./.github/scripts/pr-comment.js'); | |
return await script({github, context, state: 'finished', | |
pr_number: ${{ needs.pr-number.outputs.result }} }); |