11
11
USER_NAME : opentelemetrybot
12
12
13
13
jobs :
14
- fix-format :
15
- name : /fix:format
14
+ pr-action :
15
+ name : Run PR action
16
16
runs-on : ubuntu-latest
17
17
18
18
if : |
19
19
github.event.issue.pull_request &&
20
- contains(github.event.comment.body, '/fix:format')
21
- permissions :
22
- contents : write
23
- pull-requests : write
24
-
25
- steps :
26
- - name : Context info
27
- run : |
28
- echo $PR_NUM
29
- echo $COMMENT
30
-
31
- - uses : actions/checkout@v4
32
-
33
- - name : Write start comment
34
- run : |
35
- gh pr comment $PR_NUM -b "You triggered fix:format action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
36
- env :
37
- GH_TOKEN : ${{ github.token }}
38
-
39
- - run : gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
40
- env :
41
- GH_TOKEN : ${{ github.token }}
42
-
43
- - name : Create NPM cache-hash input file
44
- run : |
45
- mkdir -p tmp
46
- jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json
47
-
48
- - uses : actions/setup-node@v4
49
- with :
50
- node-version-file : .nvmrc
51
- cache : npm
52
- cache-dependency-path : tmp/package-ci.json
53
-
54
- - run : |
55
- npm run format
56
- git status
57
- git branch -v
58
-
59
- - name : Commit and push changes, if any
60
- run : |
61
- git config --local user.email "$USER_EMAIL"
62
- git config --local user.name "$USER_NAME"
63
- if [[ $(git status --porcelain) ]]; then
64
- git add -A
65
- current_branch=$(git rev-parse --abbrev-ref HEAD)
66
- echo current_branch=$current_branch
67
- # gh pr checkout sets some git configs that we can use to make sure
68
- # we push to the right repo & to the right branch
69
- remote_repo=$(git config --get branch.${current_branch}.remote)
70
- echo remote_repo=$remote_repo
71
- remote_branch=$(git config --get branch.${current_branch}.merge)
72
- echo remote_branch=$remote_branch
73
- git commit -m 'Results from /fix:format'
74
- git push ${remote_repo} HEAD:${remote_branch}
75
- else
76
- echo "No changes to commit"
77
- fi
78
- env :
79
- GH_TOKEN : ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
80
-
81
- - name : Report an error in the case of failure
82
- if : ${{ failure() || cancelled() }}
83
- run : |
84
- gh pr comment $PR_NUM -b "fix:format run failed, please check $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for details"
85
- env :
86
- GH_TOKEN : ${{ github.token }}
87
-
88
- fix-refcache :
89
- name : /fix:refcache
90
- runs-on : ubuntu-latest
91
-
92
- if : |
93
- github.event.issue.pull_request &&
94
- contains(github.event.comment.body, '/fix:refcache')
20
+ startsWith(github.event.comment.body, '/fix:')
95
21
permissions :
96
22
contents : write
97
23
pull-requests : write
@@ -100,6 +26,19 @@ jobs:
100
26
DEPTH : --depth 100 # submodule clone depth
101
27
102
28
steps :
29
+ - name : Extract action name
30
+ id : extract_action_name
31
+ run : |
32
+ PR_ACTION=$(echo $COMMENT | grep -oP '/fix:\K\w+')
33
+ echo "Action is $PR_ACTION"
34
+ ACTION_NAMES="format|submodules|refcache|all"
35
+ if [[ ! "$PR_ACTION" =~ ^($ACTION_NAMES)$ ]]; then
36
+ echo "Invalid action name: $PR_ACTION"
37
+ echo "Action name should be one of: $ACTION_NAMES"
38
+ exit 1
39
+ fi
40
+ echo "PR_ACTION=$PR_ACTION" >> "$GITHUB_ENV"
41
+
103
42
- name : Context info
104
43
run : |
105
44
echo $PR_NUM
@@ -109,12 +48,10 @@ jobs:
109
48
110
49
- name : Write start comment
111
50
run : |
112
- gh pr comment $PR_NUM -b "You triggered fix:refcache action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
51
+ gh pr comment $PR_NUM -b "You triggered fix:${PR_ACTION} action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
113
52
env :
114
53
GH_TOKEN : ${{ github.token }}
115
54
116
- # By providing a branch name the checkout will not break if a branch with the
117
- # same name exists already upstream (e.g. patch-X)
118
55
- run : gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
119
56
env :
120
57
GH_TOKEN : ${{ github.token }}
@@ -130,9 +67,25 @@ jobs:
130
67
cache : npm
131
68
cache-dependency-path : tmp/package-ci.json
132
69
133
- - run : npm install --omit=optional
134
70
- run : |
135
- npm run check:links
71
+ case $PR_ACTION in
72
+ format)
73
+ npm run format
74
+ ;;
75
+ submodules)
76
+ npm run sync
77
+ ;;
78
+ refcache)
79
+ npm install --omit=optional
80
+ npm run check:links
81
+ ;;
82
+ all)
83
+ npm install --omit=optional
84
+ npm run sync
85
+ npm run format
86
+ npm run check:links
87
+ ;;
88
+ esac
136
89
git status
137
90
git branch -v
138
91
@@ -150,7 +103,7 @@ jobs:
150
103
echo remote_repo=$remote_repo
151
104
remote_branch=$(git config --get branch.${current_branch}.merge)
152
105
echo remote_branch=$remote_branch
153
- git commit -m ' Results from /fix:refcache'
106
+ git commit -m " Results from /fix:${PR_ACTION}"
154
107
git push ${remote_repo} HEAD:${remote_branch}
155
108
else
156
109
echo "No changes to commit"
@@ -161,6 +114,6 @@ jobs:
161
114
- name : Report an error in the case of failure
162
115
if : ${{ failure() || cancelled() }}
163
116
run : |
164
- gh pr comment $PR_NUM -b "fix:recache run failed, please check $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for details"
117
+ gh pr comment $PR_NUM -b "fix:${PR_ACTION} run failed, please check $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for details"
165
118
env :
166
119
GH_TOKEN : ${{ github.token }}
0 commit comments