|
| 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 |
0 commit comments