forked from transmission/transmission
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (145 loc) · 5.39 KB
/
webapp.yml
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
name: webapp
on:
push:
branches:
- 'main'
paths-ignore:
- 'docs/**'
- '.github/**'
pull_request:
branches:
- 'main'
paths-ignore:
- 'docs/**'
- '.github/**'
jobs:
decide-what-jobs-to-run:
runs-on: ubuntu-22.04
outputs:
test-style: ${{ steps.check-diffs.outputs.web-changed == '1' }}
test-generated-files: ${{ steps.check-diffs.outputs.web-changed == '1' && steps.check-main-push.outputs.is-main-push == '0'}}
update-generated-files: ${{ steps.check-diffs.outputs.web-changed == '1' && steps.check-main-push.outputs.is-main-push == '1'}}
steps:
- name: Get source
uses: actions/checkout@v3
with:
fetch-depth: 2 # >1 needed for merge base
- name: Check push-to-main
id: check-main-push
run: |
set -x # echo all executed commands to the terminal
if [ "$GITHUB_EVENT_NAME" = 'push' ] && [ "$GITHUB_REF_NAME" = 'main' ]; then
echo is-main-push=1 >> "$GITHUB_OUTPUT"
else
echo is-main-push=0 >> "$GITHUB_OUTPUT"
fi
- name: Check for diffs
id: check-diffs
run: |
set -x # echo all executed commands to the terminal
function get_changes() { # name, paths...
local name="$1"
shift
if [ "$GITHUB_EVENT_NAME" = 'push' ] && [ "$GITHUB_REF_NAME" = 'main' ]; then
DIFF_TARGET='--name-only HEAD^'
else
git fetch --depth=1 origin "$GITHUB_BASE_REF"
DIFF_TARGET="--merge-base origin/$GITHUB_BASE_REF"
fi
set +e # do not abort if git --exit-code returns nonzero
git diff --exit-code ${DIFF_TARGET} -- "$@"
echo "$name-changed=$?" >> "$GITHUB_OUTPUT"
}
get_changes web CMakeLists.txt web
code-style:
runs-on: ubuntu-latest
needs: [ decide-what-jobs-to-run ]
if: ${{ needs.decide-what-jobs-to-run.outputs.test-style == 'true' }}
steps:
- name: Get source
uses: actions/checkout@v3
- name: Get dependencies
run: |
set -e # abort if any command fails
sudo apt-get install -y npm
- name: Check for style diffs
id: check-for-diffs
run: |
set -x # echo all executed commands to the terminal
set -e # abort if any command fails
npm --prefix web ci
npm --prefix web run lint:fix
set +e # do not end the script if a cmd returns an exit code
git diff --exit-code web > style.diff
echo "differs=$?" >> $GITHUB_OUTPUT
echo ===
cat style.diff
echo ===
set -e # undo set +e
- name: Upload diffs
uses: actions/upload-artifact@v3
if: ${{ steps.check-for-diffs.outputs.differs == '1' }}
with:
name: code-style.diff
path: 'style.diff'
- name: Fail if diffs exist
if: ${{ steps.check-for-diffs.outputs.differs == '1' }}
run: |
echo "code style does not match expected."
cat style.diff
echo "When CI is done, the above patch will be uploaded as 'code-style.diff' to https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/ ."
exit 1
test-generated-files:
runs-on: ubuntu-latest
needs: [ decide-what-jobs-to-run ]
if: ${{ needs.decide-what-jobs-to-run.outputs.test-generated-files == 'true' }}
steps:
- name: Get source
uses: actions/checkout@v3
with:
fetch-depth: 2 # >1 needed for merge base
- name: Check for changes to generated files
run: |
git fetch --quiet --depth=1 origin "$GITHUB_BASE_REF"
set -e # abort if diff --exit-code fails
echo
echo Hello, code contributor!
echo For security reasons, ${GITHUB_REPOSITORY} does not accept PRs that change generated files.
echo
echo Please undo your changes to these files:
git diff --exit-code --name-only --merge-base "origin/$GITHUB_BASE_REF" -- \
web/public_html/transmission-app.js \
web/public_html/transmission-app.js.map \
web/public_html/transmission-app.js.LICENSE.txt
update-generated-files:
runs-on: ubuntu-latest
needs: [ decide-what-jobs-to-run ]
if: ${{ needs.decide-what-jobs-to-run.outputs.update-generated-files == 'true' }}
steps:
- name: Show env
run: |
env | sort
- name: Get dependencies
run: |
set -e # abort if any command fails
sudo apt-get install -y npm
- name: Get source
uses: actions/checkout@v3
with:
fetch-depth: 2 # >1 needed for merge base
- name: Generate webapp files
run: |
set -x # echo all executed commands to the terminal
set -e # abort if any command fails
npm --prefix web ci
npm --prefix web run build
git diff --name-only
git add --update web
- name: Create pull request
uses: peter-evans/create-pull-request@v4
with:
branch: 'chore/update-webapp-files'
commit-message: 'chore: update generated transmission-web files'
delete-branch: true
title: 'chore: update generated transmission-web files'
body: Generated from https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}