-
Notifications
You must be signed in to change notification settings - Fork 289
132 lines (116 loc) · 4.79 KB
/
update-javascript-on-main.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
# Script to update files that should have been automatically generated.
name: Automatically update generated files
on:
push:
branches: [ main ]
pull_request_target:
branches: [ main ]
types: [opened, synchronize, reopened]
jobs:
autopr:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write
# For commenting on a PR
pull-requests: write
steps:
- name: Print event (for debugging)
run: cat $GITHUB_EVENT_PATH
#----------------------------------------------------------------------
# Either use HEDY_BOT_TOKEN or GITHUB_TOKEN
# GITHUB_TOKEN can do fewer things (push to main, trigger new GHAs, etc).
- name: Check for presence of GitHub Token
id: secret
run: |
if [ ! -z "${{ secrets.HEDY_BOT_TOKEN }}" ]; then
echo "We have a token!"
echo "secret=${{ secrets.HEDY_BOT_TOKEN }}" >> $GITHUB_OUTPUT
else
echo "We do not have a token"
echo "secret=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
fi
- name: Determine branch name
id: branch
run: |
if [[ "${{ github.event_name }}" == "pull_request"* ]]; then
echo "Pull Request"
echo "branch=$PULL_REQUEST_HEAD_REF" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "push" ]]; then
echo "Push Event"
echo "branch=${{ github.ref }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.repository.full_name }}" >> $GITHUB_OUTPUT
else
echo "Unsupported event type!" >&2
exit 1
fi
env:
# Necessary to pass like this to avoid shell script injection
PULL_REQUEST_HEAD_REF: ${{ github.event.pull_request.head.ref }}
#----------------------------------------------------------------------
# Checkout source
#
# We need to pass the token here -- the commit action below will not overwrite the token to push.
# This is necessary to bypass branch protection (which will disallow non-reviewed pushes otherwise)
#
# Make a distinction between Pull Request checkout and Push checkout. Push checkout
# works mostly automatically, but for PRs we must be very explicit to get the right
# branch and also support forks.
- uses: actions/checkout@v4
name: Checkout branch
with:
fetch-depth: 1
ref: ${{ steps.branch.outputs.branch }}
repository: ${{ steps.branch.outputs.repo }}
token: ${{ steps.secret.outputs.secret }}
#----------------------------------------------------------------------
# Actual build
- name: Set up Python 3.12
uses: actions/setup-python@v1
with:
python-version: 3.12
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
#----------------------------------------------------------------------
# Set up cache so that running snippet tests is somewhat cheap
- name: Calculate hedy cache key
run: "echo value=$(ls -1 hedy.py hedy_*.py grammars/* | sort | xargs tail -n 99999999 | sha256sum | cut -f 1 -d ' ') >> $GITHUB_OUTPUT"
id: hedy_cache_key
- name: Cache hedy test runs
uses: actions/cache@v3
with:
path: .test-cache
key: "hedy-test-cache-${{ steps.hedy_cache_key.outputs.value }}"
- name: Automatically update generated files
run: |
doit run _autopr
- name: Automatically update generated files (for Weblate PRs)
if: |
github.event.pull_request.user.login == 'weblate' ||
contains(github.event.pull_request.labels.*.name, 'translations')
run: |
doit run _autopr_weblate
- name: Prepare comment
if: ${{ hashFiles('snippet-report.md.tmp') != '' }}
run: |
echo 'The automatic script made changes' >> comment.md.tmp
cat snippet-report.md.tmp >> comment.md.tmp
- name: Post comment
if: ${{ hashFiles('comment.md.tmp') != '' && github.event_name == 'pull_request_target' }}
uses: thollander/actions-comment-pull-request@v2
with:
filePath: comment.md.tmp
#----------------------------------------------------------------------
# Commit back
# For some reason, we must supply the token here again, even though
# we already supplied it during checkout.
- name: Commit changed files (with token)
uses: stefanzweifel/git-auto-commit-action@v2.3.0
with:
commit_message: 🤖 Automatically update generated files
branch: ${{ steps.branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ steps.secret.outputs.secret }}