Repository navigation
83 lines (73 loc) · 3.5 KB
/
Copy pathupdate-wp-polyfill-modules.yml
File metadata and controls
83 lines (73 loc) · 3.5 KB
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
name: Update wp-polyfill modules
on:
workflow_dispatch:
schedule:
- cron: '41 3 * * 1'
concurrency:
group: update-wp-polyfill-modules-${{ github.ref }}
# Pushing and opening the PR use secrets.API_TOKEN_GITHUB, so no need for permissions.
permissions: {}
env:
BRANCH: update/wp-polyfill-modules
MODULES_FILE: projects/js-packages/webpack-config/src/babel/wp-polyfill-modules.json
CHANGE_FILE_PREFIX: projects/js-packages/webpack-config/changelog/update-wp-polyfill-modules
GIT_AUTHOR_NAME: matticbot
GIT_AUTHOR_EMAIL: matticbot@users.noreply.github.com
GIT_COMMITTER_NAME: matticbot
GIT_COMMITTER_EMAIL: matticbot@users.noreply.github.com
jobs:
update:
name: Update wp-polyfill modules
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
# Use the matticbot token so CI runs on the created PR.
token: ${{ secrets.API_TOKEN_GITHUB }}
- name: Setup tools
uses: $/.github/actions/tool-setup
with:
php: false
- name: Regenerate the module list
run: node projects/js-packages/webpack-config/tools/update-wp-polyfill-modules.mjs
- name: Create or update the PR
env:
GH_TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
run: |
if git diff --quiet --exit-code -- "$MODULES_FILE"; then
echo "::notice::The module list is up to date."
exit 0
fi
PR_ID=
if git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "$BRANCH" >/dev/null; then
HAS_BRANCH=true
PR_ID="$( gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number // empty' )"
if [[ -n "$PR_ID" ]] && git diff --quiet --exit-code "origin/$BRANCH" -- "$MODULES_FILE"; then
echo "::notice::PR #$PR_ID is already up to date with these changes."
exit 0
fi
else
HAS_BRANCH=false
fi
# -B resets the branch to trunk when it already exists.
git checkout -B "$BRANCH"
# Use a timestamp to prevent accidentally overwriting an entry from an earlier PR.
CHANGE_FILE="$CHANGE_FILE_PREFIX-$( date -u +%Y%m%d%H%M%S )"
printf 'Significance: patch\nType: changed\n\nBabel preset: Update the list of polyfills that WordPress includes in `wp-polyfill`.\n' > "$CHANGE_FILE"
git add -- "$MODULES_FILE" "$CHANGE_FILE"
git commit -m 'webpack-config: Update wp-polyfill modules'
if $HAS_BRANCH; then
git push --force-with-lease origin "$BRANCH"
else
git push origin "$BRANCH"
fi
if [[ -z "$PR_ID" ]]; then
if ! gh pr create --base trunk --title 'webpack-config: Update wp-polyfill modules' --body 'The `wp-polyfill` script in a supported WordPress release contains a different set of polyfills, so this updates the list the Babel preset uses to decide when to depend on it. This PR was automatically generated by the "Update wp-polyfill modules" workflow. If closed, it will be recreated the next time the workflow finds changes.' --label '[Pri] Normal' --label 'Task' --label '[Status] Needs Review' --reviewer Automattic/jetpack-monorepo; then
# Only clean up the branch if this run created it.
if ! $HAS_BRANCH; then
git push --delete origin "$BRANCH"
fi
exit 1
fi
fi