-
Notifications
You must be signed in to change notification settings - Fork 522
94 lines (83 loc) · 2.86 KB
/
publish-on-pr-merge.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
name: Sync versions on PR merge
on:
push:
branches: [master]
permissions:
id-token: write
contents: write
env:
NODE_VERSION: 17.0.1
ANCHOR_VERSION: 0.26.0
SOLANA_VERSION_STABLE: 1.14.13
RUST_TOOLCHAIN: stable
jobs:
dump-context:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
get-pr-number:
runs-on: ubuntu-latest
outputs:
pull-number: ${{ steps.get-pr-for-commit.outputs.pull-number }}
steps:
- uses: actions/checkout@v3
- name: Get PR for push event HEAD commit
uses: ./.github/actions/get-pr-for-commit
id: get-pr-for-commit
with:
commit-sha: ${{ github.sha }}
# alt: on version, publish comment or label and then parse here.
get-changes-scope:
if: ${{ jobs.get-pr-number.outputs.pull-number }} != -1
runs-on: ubuntu-latest
outputs:
changed-packages: ${{ steps.get-changed-package-scope.outputs.result }}
steps:
- uses: actions/checkout@v3
# - name: Get PR for push event HEAD commit
# uses: ./.github/actions/get-pr-for-commit
# id: get-pr-for-commit
# with:
# commit-sha: ${{ github.sha }}
- name: List changed files
uses: ./.github/actions/list-changed-files
id: list-changed-files
with:
pull-number: ${{ jobs.get-pr-number.outputs.pull-number }}
# only include files which might contain version bumps
include: '["package.json", "Cargo.toml"]'
# 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
}, {})
return Array.from(Object.keys(uniqueFilesObj))
publish-version-changes:
if: ${{ jobs.get-pr-number.outputs.pull-number }} != -1
needs: [get-changes-scope]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish version changes
uses: ./.github/actions/publish-version-changes
id: publish-version-changes
with:
changed-packages: ${{ needs.get-changes-scope.outputs.changed-packages }}
cargo-token: ${{ secrets.CARGO_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}