-
Notifications
You must be signed in to change notification settings - Fork 1.3k
166 lines (141 loc) · 5.36 KB
/
pr-actions.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: PR actions
on:
issue_comment:
types: [created]
env:
COMMENT: ${{ github.event.comment.body }}
PR_NUM: ${{ github.event.issue.number }}
USER_EMAIL: [email protected]
USER_NAME: opentelemetrybot
jobs:
fix-format:
name: /fix:format
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/fix:format')
permissions:
contents: write
pull-requests: write
steps:
- name: Context info
run: |
echo $PR_NUM
echo $COMMENT
- uses: actions/checkout@v4
- name: Write start comment
run: |
gh pr comment $PR_NUM -b "You triggered fix:format action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
env:
GH_TOKEN: ${{ github.token }}
- run: gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
env:
GH_TOKEN: ${{ github.token }}
- name: Create NPM cache-hash input file
run: |
mkdir -p tmp
jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: tmp/package-ci.json
- run: |
npm run format
git status
git branch -v
- name: Commit and push changes, if any
run: |
git config --local user.email "$USER_EMAIL"
git config --local user.name "$USER_NAME"
if [[ $(git status --porcelain) ]]; then
git add -A
current_branch=$(git rev-parse --abbrev-ref HEAD)
echo current_branch=$current_branch
# gh pr checkout sets some git configs that we can use to make sure
# we push to the right repo & to the right branch
remote_repo=$(git config --get branch.${current_branch}.remote)
echo remote_repo=$remote_repo
remote_branch=$(git config --get branch.${current_branch}.merge)
echo remote_branch=$remote_branch
git commit -m 'Results from /fix:format'
git push ${remote_repo} HEAD:${remote_branch}
else
echo "No changes to commit"
fi
env:
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
- name: Report an error in the case of failure
if: ${{ failure() || cancelled() }}
run: |
gh pr comment $PR_NUM -b "fix:format run failed, please check $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for details"
env:
GH_TOKEN: ${{ github.token }}
fix-refcache:
name: /fix:refcache
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/fix:refcache')
permissions:
contents: write
pull-requests: write
env:
DEPTH: --depth 100 # submodule clone depth
steps:
- name: Context info
run: |
echo $PR_NUM
echo $COMMENT
- uses: actions/checkout@v4
- name: Write start comment
run: |
gh pr comment $PR_NUM -b "You triggered fix:refcache action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
env:
GH_TOKEN: ${{ github.token }}
# By providing a branch name the checkout will not break if a branch with the
# same name exists already upstream (e.g. patch-X)
- run: gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
env:
GH_TOKEN: ${{ github.token }}
- name: Create NPM cache-hash input file
run: |
mkdir -p tmp
jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: tmp/package-ci.json
- run: npm install --omit=optional
- run: |
npm run check:links
git status
git branch -v
- name: Commit and push changes, if any
run: |
git config --local user.email "$USER_EMAIL"
git config --local user.name "$USER_NAME"
if [[ $(git status --porcelain) ]]; then
git add -A
current_branch=$(git rev-parse --abbrev-ref HEAD)
echo current_branch=$current_branch
# gh pr checkout sets some git configs that we can use to make sure
# we push to the right repo & to the right branch
remote_repo=$(git config --get branch.${current_branch}.remote)
echo remote_repo=$remote_repo
remote_branch=$(git config --get branch.${current_branch}.merge)
echo remote_branch=$remote_branch
git commit -m 'Results from /fix:refcache'
git push ${remote_repo} HEAD:${remote_branch}
else
echo "No changes to commit"
fi
env:
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
- name: Report an error in the case of failure
if: ${{ failure() || cancelled() }}
run: |
gh pr comment $PR_NUM -b "fix:recache run failed, please check $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for details"
env:
GH_TOKEN: ${{ github.token }}