@@ -5,38 +5,111 @@ concurrency:
5
5
cancel-in-progress : true
6
6
7
7
on :
8
- pull_request_review :
9
- branches : [ 'main' ]
10
- types : [submitted]
8
+ workflow_run :
9
+ workflows : ["On PR Approved"]
10
+ types :
11
+ - completed
11
12
12
13
jobs :
13
14
compile-protos :
14
- if : github.event.review.state == 'approved' && github.repository_owner == 'viamrobotics'
15
+ if : >
16
+ github.event.workflow_run.event == 'pull_request_review' &&
17
+ github.event.workflow_run.conclusion == 'success'
15
18
runs-on : [self-hosted, x64]
16
19
container :
17
20
image : ghcr.io/viamrobotics/canon:amd64-cache
18
21
options : --platform linux/amd64
22
+ env :
23
+ CI_COMMIT_MESSAGE_PREFIX : Built new protos from
24
+ CI_COMMIT_AUTHOR : github-actions
25
+ LABEL_NAME : protos-compiled
19
26
steps :
27
+ # Download PR info from approval workflow and checkout branch
28
+ - name : Download artifact
29
+ uses : dawidd6/action-download-artifact@v2
30
+ with :
31
+ run_id : ${{github.event.workflow_run.id }}
32
+ - name : Get PR Repo
33
+ id : get-pr-repo
34
+ uses : actions/github-script@v6
35
+ with :
36
+ result-encoding : string
37
+ script : |
38
+ var fs = require('fs');
39
+ var repo = String(fs.readFileSync('./pr/repo')).trim();
40
+ return repo
41
+ - name : Get PR Ref
42
+ id : get-pr-ref
43
+ uses : actions/github-script@v6
44
+ with :
45
+ result-encoding : string
46
+ script : |
47
+ var fs = require('fs');
48
+ var ref = String(fs.readFileSync('./pr/ref')).trim();
49
+ return ref
50
+ - name : Get PR Number
51
+ id : get-pr-number
52
+ uses : actions/github-script@v6
53
+ with :
54
+ script : |
55
+ var fs = require('fs');
56
+ var number = Number(String(fs.readFileSync('./pr/number')).trim());
57
+ return number
20
58
- uses : actions/checkout@v3
21
59
with :
22
- repository : ${{ github.event.pull_request.head. repo.full_name }}
23
- ref : ${{ github.event.pull_request.head.ref }}
60
+ repository : ${{ steps.get-pr- repo.outputs.result }}
61
+ ref : ${{ steps.get-pr-ref.outputs.result }}
24
62
token : ${{ secrets.REPO_READ_TOKEN }}
63
+
64
+ # Set environment variables based on the last commit
65
+ - name : Set environment variable "commit-message"
66
+ run : echo "commit-message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV
67
+ - name : Set environment variable "commit-author"
68
+ run : echo "commit-author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV
69
+
70
+ # If the last commit is an auto-generated commit from this workflow, we can exit early
71
+ - name : Set environment variable "is-auto-commit"
72
+ if : startsWith(env.commit-message, env.CI_COMMIT_MESSAGE_PREFIX) && env.commit-author == env.CI_COMMIT_AUTHOR
73
+ run : echo "is-auto-commit=true" >> $GITHUB_ENV
74
+
75
+ # Remove label if exists, since we're about to compile again
76
+ - name : Remove label
77
+ if : env.is-auto-commit == false
78
+
79
+ with :
80
+ repo-token : ${{ secrets.REPO_READ_TOKEN }}
81
+ remove-labels : ${{ env.LABEL_NAME }}
82
+ issue-number : ${{ steps.get-pr-number.outputs.result }}
83
+
84
+ # Build and push
25
85
- uses : bufbuild/buf-setup-action@v1
86
+ if : env.is-auto-commit == false
26
87
with :
27
88
github_token : ${{ secrets.GITHUB_TOKEN }}
28
89
- uses : arduino/setup-protoc@v1
90
+ if : env.is-auto-commit == false
29
91
30
92
- name : Compile protos
93
+ if : env.is-auto-commit == false
31
94
run : make dist/buf
32
95
33
96
- name : Add SHORT_SHA env property
97
+ if : env.is-auto-commit == false
34
98
id : short_sha
35
99
run : echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
36
100
37
101
- name : Commit + Push
102
+ if : env.is-auto-commit == false
38
103
39
104
with :
40
105
default_author : github_actions
41
- message : Built new protos from ${{ steps.short_sha.outputs.short_sha }} [skip ci]
106
+ message : ${{ env.CI_COMMIT_MESSAGE_PREFIX }} ${{ steps.short_sha.outputs.short_sha }} [skip ci]
42
107
push : true
108
+
109
+ - name : Add label
110
+ if : env.is-auto-commit == false
111
+
112
+ with :
113
+ repo-token : ${{ secrets.REPO_READ_TOKEN }}
114
+ add-labels : ${{ env.LABEL_NAME }}
115
+ issue-number : ${{ steps.get-pr-number.outputs.result }}
0 commit comments