-
Notifications
You must be signed in to change notification settings - Fork 24
83 lines (71 loc) · 2.46 KB
/
non-api-call.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
name: Update nonAPI.txt
on:
# Run this weekly
schedule:
- cron: '42 12 * * 1'
# This can also manually run
workflow_dispatch: {}
jobs:
update_nonAPI_txt:
runs-on: ${{ matrix.config.os }}
name: Update nonAPI.txt on ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest}
- {os: macOS-latest}
- {os: ubuntu-latest}
steps:
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: 'devel'
- name: Update nonAPI.txt
run: |
# Update the non-API list first
Rscript -e 'cat(tools:::nonAPI, sep = "\n")' | tr -d '\r' | sort -u | tee ./nonAPI.txt
shell: bash
- name: Upload nonAPI.txt
uses: actions/upload-artifact@v3
with:
name: nonAPI-${{ matrix.config.os }}
path: nonAPI.txt
commit_nonAPI_txt:
needs: update_nonAPI_txt
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- name: Switch branch
run: |
# 1) If there's already update_nonAPI_txt branch, checkout it.
# 2) If update_nonAPI_txt branch is not created, create it from the default branch.
if git ls-remote --exit-code --heads origin update_nonAPI_txt 2>&1 >/dev/null; then
git fetch origin --no-tags --prune --depth=1 update_nonAPI_txt
git checkout update_nonAPI_txt
else
git switch -c update_nonAPI_txt
fi
- name: Commit and create a pull request
run: |
# Merge all nonAPI.txt
cat nonAPI-*/nonAPI.txt | tr -d '\r' | sort -u | tee nonAPI.txt
# detect changes (the code is derived from https://stackoverflow.com/a/3879077)
git add nonAPI.txt
git update-index --refresh
if ! git diff-index --quiet HEAD -- nonAPI.txt; then
# commit
git config --local user.name "${GITHUB_ACTOR}"
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "nonAPI.txt [skip ci]"
# push to the origin
git push origin update_nonAPI_txt
# create the pull request
gh pr create --title "Update nonAPI.txt" --body "Please review the diff and run /bindings command manually."
else
echo "No changes"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}