Skip to content

Commit e63a453

Browse files
authored
Add workflow for maintaining floating tags (#234)
1 parent a1d4890 commit e63a453

File tree

2 files changed

+84
-26
lines changed

2 files changed

+84
-26
lines changed

.github/workflows/tag.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'tag'
2+
3+
on:
4+
push:
5+
tags:
6+
# match vx.y and v x.y.z.w... but not vx
7+
- 'v[0-9]+.*'
8+
9+
jobs:
10+
# pointer parses the incoming tag value and updates the "vX" pointer to the
11+
# same SHA as this tag.
12+
pointer:
13+
name: 'pointer'
14+
runs-on: 'ubuntu-latest'
15+
steps:
16+
- uses: 'actions/github-script@v5'
17+
with:
18+
script: |-
19+
const tag = process.env.GITHUB_REF_NAME;
20+
if(!tag) {
21+
core.setFailed(`Missing tag!`)
22+
return
23+
}
24+
core.info(`Using tag "${tag}"`)
25+
26+
const matches = tag.match(/(v[0-9]+).*/)
27+
if(!matches || matches.length < 2) {
28+
core.setFailed(`Invalid tag "${tag}"`)
29+
return
30+
}
31+
const major = matches[1];
32+
core.info(`Matched to major tag "${major}"`)
33+
34+
// Try to update the ref first. If that fails, it probably does not
35+
// exist yet, and we should create it.
36+
try {
37+
await github.rest.git.updateRef({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
ref: `tags/${major}`,
41+
sha: context.sha,
42+
force: true,
43+
})
44+
45+
core.info(`Updated "${major}" to "${tag}" (${context.sha})`)
46+
} catch {
47+
core.warning(`Failed to update "${major}" tag (it may not `+
48+
`exist). Trying to create "${major}" now.`)
49+
50+
await github.rest.git.createRef({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
ref: `refs/tags/${major}`,
54+
sha: context.sha,
55+
})
56+
57+
core.info(`Created "${major}" at "${tag}" (${context.sha})`)
58+
}

README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ jobs:
4545
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
4646
service_account: 'my-service-account@my-project.iam.gserviceaccount.com'
4747

48-
- id: deploy
49-
uses: google-github-actions/deploy-cloud-functions@v0.7.0
48+
- id: 'deploy'
49+
uses: 'google-github-actions/deploy-cloud-functions@v0'
5050
with:
51-
name: my-function
52-
runtime: nodejs10
51+
name: 'my-function'
52+
runtime: 'nodejs12'
5353

5454
# Example of using the output
55-
- id: test
56-
run: curl "${{ steps.deploy.outputs.url }}"
55+
- id: 'test'
56+
run: 'curl "${{ steps.deploy.outputs.url }}"'
5757
```
5858
5959
## Inputs
@@ -221,19 +221,19 @@ jobs:
221221
id-token: 'write'
222222
223223
steps:
224-
- uses: actions/checkout@v2
224+
- uses: 'actions/checkout@v2'
225225
226-
- id: auth
227-
uses: google-github-actions/auth@v0
226+
- id: 'auth'
227+
uses: 'google-github-actions/auth@v0'
228228
with:
229229
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
230230
service_account: 'my-service-account@my-project.iam.gserviceaccount.com'
231231
232-
- id: deploy
233-
uses: google-github-actions/deploy-cloud-functions@v0.7.0
232+
- id: 'deploy'
233+
uses: 'google-github-actions/deploy-cloud-functions@v0'
234234
with:
235-
name: my-function
236-
runtime: nodejs10
235+
name: 'my-function'
236+
runtime: 'nodejs12'
237237
```
238238

239239
#### Authenticating via Service Account Key JSON
@@ -242,18 +242,18 @@ jobs:
242242
jobs:
243243
job_id:
244244
steps:
245-
- uses: actions/checkout@v2
245+
- uses: 'actions/checkout@v2'
246246
247-
- id: auth
248-
uses: google-github-actions/auth@v0
247+
- id: 'auth'
248+
uses: 'google-github-actions/auth@v0'
249249
with:
250-
credentials_json: ${{ secrets.gcp_credentials }}
250+
credentials_json: '${{ secrets.gcp_credentials }}'
251251
252-
- id: deploy
253-
uses: google-github-actions/deploy-cloud-functions@v0.7.0
252+
- id: 'deploy'
253+
uses: 'google-github-actions/deploy-cloud-functions@v0'
254254
with:
255-
name: my-function
256-
runtime: nodejs10
255+
name: 'my-function'
256+
runtime: 'nodejs12'
257257
```
258258

259259
### Via Application Default Credentials
@@ -267,13 +267,13 @@ only works using a custom runner hosted on GCP.**
267267
jobs:
268268
job_id:
269269
steps:
270-
- uses: actions/checkout@v2
270+
- uses: 'actions/checkout@v2'
271271
272-
- id: Deploy
273-
uses: google-github-actions/deploy-cloud-functions@v0.7.0
272+
- id: 'deploy'
273+
uses: 'google-github-actions/deploy-cloud-functions@v0'
274274
with:
275-
name: my-function
276-
runtime: nodejs10
275+
name: 'my-function'
276+
runtime: 'nodejs12'
277277
```
278278

279279
The action will automatically detect and use the Application Default

0 commit comments

Comments
 (0)