Skip to content

Commit 256c06e

Browse files
authored
Add workflow to tag floating aliases (#260)
1 parent ee787e6 commit 256c06e

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed

.github/workflows/example-workflow-quickstart.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ jobs:
2323
deploy:
2424
runs-on: ubuntu-latest
2525
steps:
26-
26+
2727
- name: Deploy to Cloud Run
2828
id: deploy
29-
uses: google-github-actions/deploy-cloudrun@v0.2.0
29+
uses: google-github-actions/deploy-cloudrun@v0
3030
with:
3131
image: gcr.io/cloudrun/hello
3232
service: hello-cloud-run
3333
credentials: ${{ secrets.GCP_SA_KEY }}
3434

3535
- name: Show Output
3636
run: echo ${{ steps.deploy.outputs.url }}
37-

.github/workflows/example-workflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
4848
- name: Deploy to Cloud Run
4949
id: deploy
50-
uses: google-github-actions/deploy-cloudrun@v0.4.0
50+
uses: google-github-actions/deploy-cloudrun@v0
5151
with:
5252
service: ${{ env.SERVICE }}
5353
image: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}

.github/workflows/tag.yml

Lines changed: 58 additions & 0 deletions
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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
service_account: '[email protected]'
6161

6262
- id: 'deploy'
63-
uses: 'google-github-actions/deploy-cloudrun@v0.6.0'
63+
uses: 'google-github-actions/deploy-cloudrun@v0'
6464
with:
6565
service: 'hello-cloud-run'
6666
image: 'gcr.io/cloudrun/hello'
@@ -169,7 +169,7 @@ jobs:
169169
service_account: '[email protected]'
170170
171171
- name: 'Deploy to Cloud Run'
172-
uses: 'google-github-actions/deploy-cloudrun@v0.6.0'
172+
uses: 'google-github-actions/deploy-cloudrun@v0'
173173
with:
174174
image: 'gcr.io/cloudrun/hello'
175175
service: 'hello-cloud-run'
@@ -187,7 +187,7 @@ jobs:
187187
credentials_json: '${{ secrets.GCP_SA_KEY }}'
188188
189189
- name: 'Deploy to Cloud Run'
190-
uses: 'google-github-actions/deploy-cloudrun@v0.6.0'
190+
uses: 'google-github-actions/deploy-cloudrun@v0'
191191
with:
192192
image: 'gcr.io/cloudrun/hello'
193193
service: 'hello-cloud-run'
@@ -205,7 +205,7 @@ jobs:
205205
job_id:
206206
steps:
207207
- name: 'Deploy to Cloud Run'
208-
uses: 'google-github-actions/deploy-cloudrun@v0.6.0'
208+
uses: 'google-github-actions/deploy-cloudrun@v0'
209209
with:
210210
image: 'gcr.io/cloudrun/hello'
211211
service: 'hello-cloud-run'
@@ -294,7 +294,7 @@ jobs:
294294
credentials_json: '${{ secrets.GCP_SA_KEY }}'
295295
296296
- name: 'Deploy to Cloud Run'
297-
uses: 'google-github-actions/deploy-cloudrun@v0.6.0'
297+
uses: 'google-github-actions/deploy-cloudrun@v0'
298298
with:
299299
service: '${{ env.SERVICE }}'
300300
image: 'gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}'

0 commit comments

Comments
 (0)