forked from erlang/otp
-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (146 loc) · 5.81 KB
/
pr-comment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
## %CopyrightBegin%
##
## Copyright Ericsson AB 2024. All Rights Reserved.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## %CopyrightEnd%
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
permissions:
contents: read
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/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet: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/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/[email protected]
## We create an initial comment with some useful help to the user
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # ratchet: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/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet: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/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/[email protected]
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@170bf24d20d201b842d7a52403b73ed297e6645b # ratchet: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/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # ratchet: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 }} });