130 lines (130 loc) · 4.96 KB
/
release-submodule.yaml
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
# This action looks at the commit history since the last release, and uses
# this to decide which submodules require an update:
on:
push:
branches:
- master
name: release-please-submodule
jobs:
# This logic looks at commits that have occurred since GitHub's magic
# latestRelease:
# https://developer.github.com/v3/repos/releases/#get-the-latest-release
# TODO: it would be better if we retrieved a list of all prior releases,
# and found the oldest release within the SUB_MODULES array. We need this
# logic for other libraries as well, and would like to pull this logic
# into its own action.
changeFinder:
runs-on: ubuntu-latest
outputs:
submodules: ${{ steps.interrogate.outputs.submodules }}
steps:
- uses: actions/checkout@v2
- id: interrogate
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const {execSync} = require('child_process');
const SUB_MODULES = [
'bigtable',
'bigquery',
'datastore',
'firestore',
'logging',
'pubsub',
'pubsublite',
'spanner',
'storage',
];
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const latestRelease = await github.repos.getLatestRelease({
owner,
repo
});
console.info(`latest release: ${latestRelease.data.tag_name}`);
// pull all tags, so we can get diff between HEAD and last release:
execSync('git pull --tags');
execSync(`git reset --hard ${latestRelease.data.tag_name}`);
const status = execSync(`git diff --name-only origin/master`, { encoding: 'utf-8'});
console.info(status);
const changes = status.split('\n');
const submodules = new Set();
for (const change of changes) {
const library = change.split('/')[0];
console.info(`update to path ${library}`);
if (SUB_MODULES.includes(library)) {
submodules.add(library);
}
}
console.log(`::set-output name=submodules::${JSON.stringify(Array.from(submodules))}`);
release-pr: # Create the release PR based on commit history:
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.changeFinder.outputs.submodules)}}
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: release-please
with:
path: ${{ matrix.package }}
token: ${{ secrets.FORKING_TOKEN }}
fork: true
release-type: go
package-name: ${{ matrix.package }}
monorepo-tags: true
command: release-pr
- uses: actions/github-script@v3
id: label # Adds the "autorelease: pending" label.
if: ${{steps.release-please.outputs.pr}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const latestRelease = await github.issues.addLabels({
owner,
repo,
issue_number: ${{steps.release-please.outputs.pr}},
labels: ['autorelease: pending']
});
console.log(`Tagged ${{steps.release-please.outputs.pr}}`)
release-please-release: # Actually create a release tag.
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.changeFinder.outputs.submodules)}}
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: tag-release
with:
path: ${{ matrix.package }}
token: ${{ secrets.GITHUB_TOKEN }}
release-type: go
monorepo-tags: true
package-name: ${{ matrix.package }}
command: github-release
# Add the "autorelease: published" and remove tagged, this allows
# monitoring to be enabled that detects failed releases:
- uses: actions/github-script@v3
id: untag-release
if: ${{steps.tag-release.outputs.pr}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
await github.issues.addLabels({
owner,
repo,
issue_number: ${{steps.tag-release.outputs.pr}},
labels: ['autorelease: published']
});
github.issues.removeLabel({
owner,
repo,
issue_number: ${{steps.tag-release.outputs.pr}},
name: 'autorelease: tagged',
});
console.log(`Tagged ${{steps.tag-release.outputs.pr}}`)