|
| 1 | +name: release |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - "v*" |
| 6 | + |
| 7 | +permissions: |
| 8 | + # Required to publish a release |
| 9 | + contents: write |
| 10 | + # Necessary to push docker images to ghcr.io. |
| 11 | + packages: write |
| 12 | + # Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage) |
| 13 | + id-token: write |
| 14 | + |
| 15 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + name: Build and publish |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: Echo Go Cache Paths |
| 25 | + id: go-cache-paths |
| 26 | + run: | |
| 27 | + echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT |
| 28 | + echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT |
| 29 | +
|
| 30 | + - name: Go Build Cache |
| 31 | + uses: actions/cache@v3 |
| 32 | + with: |
| 33 | + path: ${{ steps.go-cache-paths.outputs.GOCACHE }} |
| 34 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }} |
| 35 | + |
| 36 | + - uses: actions/setup-go@v3 |
| 37 | + with: |
| 38 | + go-version: "~1.20" |
| 39 | + |
| 40 | + - name: Get Version |
| 41 | + run: echo "version=$(./scripts/version.sh)" >> $GITHUB_OUTPUT |
| 42 | + id: version |
| 43 | + |
| 44 | + - name: Build |
| 45 | + run: ./scripts/build.sh |
| 46 | + |
| 47 | + - name: Docker Login |
| 48 | + uses: docker/login-action@v2 |
| 49 | + with: |
| 50 | + registry: ghcr.io |
| 51 | + username: ${{ github.actor }} |
| 52 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Push Image |
| 55 | + run: | |
| 56 | + VERSION=$(./scripts/version.sh) |
| 57 | + BASE=ghcr.io/coder/coder-xray |
| 58 | + IMAGE=$BASE:$VERSION |
| 59 | + docker tag coder-xray:latest $IMAGE |
| 60 | + docker tag coder-xray:latest $BASE:latest |
| 61 | + docker push $IMAGE |
| 62 | + docker push $BASE:latest |
| 63 | +
|
| 64 | + - name: Authenticate to Google Cloud |
| 65 | + uses: google-github-actions/auth@v1 |
| 66 | + with: |
| 67 | + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_ID_PROVIDER }} |
| 68 | + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} |
| 69 | + |
| 70 | + - name: Setup GCloud SDK |
| 71 | + uses: "google-github-actions/setup-gcloud@v1" |
| 72 | + |
| 73 | + - name: Publish Helm Chart |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + version="$(./scripts/version.sh)" |
| 77 | + ./scripts/helm.sh --version $version |
| 78 | +
|
| 79 | + mkdir -p build/helm |
| 80 | + cp "build/${version}.tgz" build/helm |
| 81 | + gsutil cp gs://helm.coder.com/coder-xray/index.yaml build/helm/index.yaml |
| 82 | + helm repo index build/helm --url https://helm.coder.com/coder-xray --merge build/helm/index.yaml |
| 83 | + gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/${version}.tgz gs://helm.coder.com/coder-xray |
| 84 | + gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/coder-xray |
| 85 | +
|
| 86 | + - name: Create Release |
| 87 | + uses: actions/create-release@v1 |
| 88 | + id: create_release |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ github.token }} |
| 91 | + with: |
| 92 | + release_name: ${{ steps.version.outputs.version }} |
| 93 | + tag_name: ${{ github.ref }} |
| 94 | + |
| 95 | + - name: Upload Helm Release Asset |
| 96 | + uses: actions/upload-release-asset@v1 |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ github.token }} |
| 99 | + with: |
| 100 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 101 | + asset_path: build/${{ steps.version.outputs.version }}.tgz |
| 102 | + asset_name: helm.tar.gz |
| 103 | + asset_content_type: application/gzip |
0 commit comments