-
Notifications
You must be signed in to change notification settings - Fork 522
141 lines (128 loc) · 5.57 KB
/
apply-version-update.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
name: Apply Version Update
on:
pull_request_review:
types: [ submitted, edited ]
permissions:
id-token: write
contents: write
packages: write
issues: write # make comment
pull-requests: write # open PR
env:
NODE_VERSION: 17.0.1
ANCHOR_VERSION: 0.26.0
SOLANA_VERSION_STABLE: 1.14.13
RUST_TOOLCHAIN: stable
jobs:
dump-context:
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
get-changes-scope:
if: |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name &&
contains(fromJson('["OWNER", "MEMBER", "CONTRIBUTOR"]'), github.event.review.author_association) == true &&
contains(fromJson('["approved", "commented"]'), github.event.review.state) == true
runs-on: ubuntu-latest
outputs:
changed-packages: ${{ steps.get-changed-package-scope.outputs.packages }}
num-packages: ${{ steps.get-changed-package-scope.outputs.num-packages }}
steps:
- uses: actions/checkout@v3
- name: List changed files
uses: ./.github/actions/list-changed-files
id: list-changed-files
with:
pull-number: ${{ github.event.pull_request.number }}
# we ignore js/idl because that's an output of updating the package's rust version
# note: rust version updates also result in package.json changes, so multiple version updates
# will result in the js package also getting updated. but, i think this is ok since there
# haven't been any PRs to date with multiple version changes. and, in the long term, we
# want more granular version commands
exclude: '["js/idl"]'
# map fetched changed files to package / lang (list)
- name: Get scope of changed packages
uses: actions/github-script@v4
id: get-changed-package-scope
with:
# update regexp to consider other subdirs - e.g. `rust|test|cli|<etc>`
script: |
const files = ${{ steps.list-changed-files.outputs.changed-files }}
const regexp = /[a-zA-Z\-]+\/(js|program)/g
const uniqueFilesObj = files.reduce((p, file) => {
const match = file.match(regexp)
if (match) {
// use first match result
if (!p[match[0]]) p[match[0]] = 1
}
return p
}, {})
const changedPackages = Array.from(Object.keys(uniqueFilesObj))
core.setOutput('packages', JSON.stringify(changedPackages.map((el) => `\"${el}\"`)))
core.setOutput('num-packages', changedPackages.length)
- name: Print changed scope output
id: print-changed-scope-output
run: |
echo "num packages -> ${{ steps.get-changed-package-scope.outputs.num-packages }}"
echo "packages -> ${{ steps.get-changed-package-scope.outputs.packages }}"
shell: bash
get-version-scope:
if: |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name &&
contains(fromJson('["OWNER", "MEMBER", "CONTRIBUTOR"]'), github.event.review.author_association) == true &&
contains(fromJson('["approved", "commented"]'), github.event.review.state) == true
runs-on: ubuntu-latest
outputs:
versioning: ${{ steps.parse-version-info.outputs.versioning }}
has-versioning: ${{ steps.parse-version-info.outputs.has-versioning }}
steps:
- uses: actions/checkout@v3
# GH doesn't process or format body fields, so we do some light processing so that multiline comments will break inputs
- name: Process content body
id: process-content-body
env:
REVIEW_BODY: ${{ github.event.review.body }}
run: |
REVIEW_CONTENT=$(cat << EOF
$REVIEW_BODY
EOF
)
REVIEW_CONTENT="${REVIEW_CONTENT//\'/}"
REVIEW_CONTENT="${REVIEW_CONTENT//$'\n'/\\n}"
REVIEW_CONTENT="${REVIEW_CONTENT//$'\r'/\\r}"
echo "::set-output name=content::$REVIEW_CONTENT"
shell: bash
- name: Log processed content body
run: echo "${{ steps.process-content-body.outputs.content }}"
shell: bash
- name: Parse version info from review
uses: ./.github/actions/parse-version-command
id: parse-version-info
with:
body: ${{ steps.process-content-body.outputs.content }}
update-pr-with-changes:
needs: [ get-changes-scope, get-version-scope ]
if: needs.get-version-scope.outputs.has-versioning == 'true' && needs.get-changes-scope.outputs.num-packages > 0
runs-on: ubuntu-latest-16-cores
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-linux-build-deps
# - uses: ./.github/actions/install-solana
# with:
# solana_version: ${{ env.SOLANA_VERSION_STABLE }}
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Make version changes
uses: ./.github/actions/make-version-changes
id: make-version-changes
with:
changed-packages: ${{ needs.get-changes-scope.outputs.changed-packages }}
versioning: ${{ needs.get-version-scope.outputs.versioning }}
from-branch: ${{ github.event.pull_request.head.ref }}
from-repository: ${{ github.event.pull_request.head.repo.full_name }}