Skip to content

Commit 1c51a1f

Browse files
authored
Merge pull request #140 from chiukapoor/gh-move-release
[GH-Action] Fix and streamline tag and release workflow
2 parents 2bd7967 + c97014b commit 1c51a1f

File tree

3 files changed

+87
-76
lines changed

3 files changed

+87
-76
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Creates a tag and upload release
2+
on: workflow_dispatch
3+
4+
jobs:
5+
validate:
6+
permissions:
7+
contents: read
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 10
10+
container:
11+
image: rancher/dapper:v0.6.0
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
- name: Validate
16+
run: dapper validate
17+
18+
tag:
19+
permissions:
20+
contents: write
21+
needs: validate
22+
runs-on: ubuntu-latest
23+
outputs:
24+
generated-tag: ${{ steps.generate_tag.outputs.generated-tag }}
25+
steps:
26+
- name: Check out repository code
27+
uses: actions/checkout@v4
28+
- name: Run tests
29+
id: generate_tag
30+
run: |
31+
tag=$(bash scripts/generate-release-tag)
32+
echo "generated-tag=$tag" >> $GITHUB_OUTPUT
33+
- uses: actions/github-script@v7.0.1
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
script: |
37+
const tag = '${{ steps.generate_tag.outputs.generated-tag }}'
38+
39+
const branch = '${{ github.ref_name }}'
40+
41+
try {
42+
const resp = await github.rest.git.getRef({...context.repo, ref: `tags/${tag}`});
43+
return core.setFailed(`the tag ${tag} already exists on ${resp.data.object.type} ${resp.data.object.sha}`);
44+
} catch(err) {
45+
if(err.status !== 404){
46+
throw err;
47+
}
48+
}
49+
50+
github.rest.git.createRef({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
ref: `refs/tags/${tag}`,
54+
sha: context.sha
55+
})
56+
57+
upload:
58+
permissions:
59+
contents: read
60+
id-token: write
61+
needs: [validate,tag]
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 10
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
- name: Add tag to version file
68+
run: |
69+
echo "{\"version\": \"${{ needs.tag.outputs.generated-tag }}\"}" > dist/VERSION
70+
- name: Retrieve Google auth from vault
71+
uses: rancher-eio/read-vault-secrets@main
72+
with:
73+
secrets: |
74+
secret/data/github/repo/${{ github.repository }}/google-auth/rancher/credentials token | GOOGLE_AUTH
75+
- name: Authenticate with Google Cloud
76+
uses: 'google-github-actions/auth@v2'
77+
with:
78+
credentials_json: '${{ env.GOOGLE_AUTH }}'
79+
- name: Upload to Google Cloud Storage
80+
uses: google-github-actions/upload-cloud-storage@v2
81+
with:
82+
path: dist/
83+
destination: releases.rancher.com/install-docker
84+
parent: false
85+
predefinedAcl: publicRead
86+
headers: |-
87+
cache-control: public,no-cache,proxy-revalidate

.github/workflows/create-tag.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/workflow.yaml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
push:
55
branches:
66
- master
7-
tags:
8-
- '*'
97
pull_request:
108
branches:
119
- master
@@ -69,38 +67,5 @@ jobs:
6967
destination: releases.rancher.com/install-docker-dev
7068
parent: false
7169
predefinedAcl: publicRead
72-
headers: |-
73-
cache-control: public,no-cache,proxy-revalidate
74-
75-
upload:
76-
permissions:
77-
contents: read
78-
id-token: write
79-
needs: validate
80-
runs-on: ubuntu-latest
81-
timeout-minutes: 10
82-
if: github.event_name == 'push' && github.ref_type == 'tag'
83-
steps:
84-
- name: Checkout code
85-
uses: actions/checkout@v4
86-
- name: Add tag to version file
87-
run: |
88-
echo "{\"version\": \"${{ github.ref_name }}\"}" > dist/VERSION
89-
- name: Retrieve Google auth from vault
90-
uses: rancher-eio/read-vault-secrets@main
91-
with:
92-
secrets: |
93-
secret/data/github/repo/${{ github.repository }}/google-auth/rancher/credentials token | GOOGLE_AUTH
94-
- name: Authenticate with Google Cloud
95-
uses: 'google-github-actions/auth@v2'
96-
with:
97-
credentials_json: '${{ env.GOOGLE_AUTH }}'
98-
- name: Upload to Google Cloud Storage
99-
uses: google-github-actions/upload-cloud-storage@v2
100-
with:
101-
path: dist/
102-
destination: releases.rancher.com/install-docker
103-
parent: false
104-
predefinedAcl: publicRead
10570
headers: |-
10671
cache-control: public,no-cache,proxy-revalidate

0 commit comments

Comments
 (0)