Update PR details #17883
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' | |
permissions: | |
issues: read | |
outputs: | |
result: ${{ steps.pr-number.outputs.result }} | |
steps: | |
- uses: actions/[email protected] | |
- 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 | |
permissions: | |
issues: write | |
pull-requests: write | |
if: github.event.action == 'requested' && needs.pr-number.outputs.result != '' | |
steps: | |
- uses: actions/[email protected] | |
## 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 | |
permissions: | |
issues: write | |
checks: write | |
pull-requests: write | |
if: >- | |
github.event.action == 'completed' && | |
needs.pr-number.outputs.result != '' && | |
github.event.workflow_run.conclusion != 'skipped' | |
steps: | |
- uses: actions/[email protected] | |
- 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/[email protected] | |
with: | |
token: ${{ secrets.ERLANG_TOKEN }} | |
repository: 'erlang/erlang.github.io' | |
path: erlang.github.io | |
- name: Publish CT Test Results | |
uses: EnricoMi/[email protected] | |
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 🚀 | |
run: | | |
cd erlang.github.io | |
set -x | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add . | |
git add -u | |
git update-index --refresh | |
if ! git diff-index --quiet HEAD --; then | |
git commit -m "Update github pages content" | |
git push origin master | |
fi | |
## Append some useful 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 }} }); |