Repository navigation
61 lines (53 loc) · 2.14 KB
/
Copy pathsync.yml
File metadata and controls
61 lines (53 loc) · 2.14 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
name: sync
# Daily: if owterminal.com serves a newer ow.mjs, open a pull request with it.
on:
schedule:
- cron: "23 6 * * *"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
concurrency:
group: sync
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
- name: Download ow.mjs
id: fetch
run: |
curl -fsSL --retry 3 https://owterminal.com/ow.mjs -o "$RUNNER_TEMP/ow.mjs"
node --input-type=module --check < "$RUNNER_TEMP/ow.mjs"
if cmp -s "$RUNNER_TEMP/ow.mjs" ow.mjs; then
echo "ow.mjs is current."
echo "changed=false" >> "$GITHUB_OUTPUT"
else
cp "$RUNNER_TEMP/ow.mjs" ow.mjs
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Open a pull request
if: steps.fetch.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
branch=sync/ow-mjs
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -C "$branch"
git add ow.mjs
git commit -m "Sync ow.mjs from owterminal.com"
git push --force origin "$branch"
open=$(gh pr list --head "$branch" --state open --json number --jq length)
if [ "$open" = "0" ]; then
# The organization may not allow Actions to open pull requests. Then the
# branch is still pushed, and the run leaves a link instead of failing.
gh pr create --base main --head "$branch" \
--title "Sync ow.mjs from owterminal.com" \
--body "owterminal.com serves a newer ow.mjs. It parses under Node 22. Add a CHANGELOG.md line before merging." \
|| echo "::warning::Could not open a pull request. Open one from $branch: https://github.com/${GITHUB_REPOSITORY}/compare/main...$branch"
fi