chore: improve release workflow (#60) #19
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
push: | |
tags: | |
- "v*" | |
permissions: | |
# Required to publish a release | |
contents: write | |
# Necessary to push docker images to ghcr.io. | |
packages: write | |
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage) | |
id-token: write | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
release: | |
name: Build and publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "~1.22" | |
- name: Get Version | |
run: echo "version=$(./scripts/version.sh)" >> $GITHUB_OUTPUT | |
id: version | |
- name: Docker Login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and Push Docker Image | |
run: ./scripts/build.sh | |
env: | |
CI: true | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_ID_PROVIDER }} | |
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
- name: Setup GCloud SDK | |
uses: "google-github-actions/setup-gcloud@v2" | |
- name: Publish Helm Chart | |
run: | | |
set -euo pipefail | |
version="$(./scripts/version.sh)" | |
./scripts/helm.sh --version $version | |
mkdir -p build/helm | |
cp "build/${version}.tgz" build/helm | |
gsutil cp gs://helm.coder.com/logstream-kube/index.yaml build/helm/index.yaml | |
helm repo index build/helm --url https://helm.coder.com/logstream-kube --merge build/helm/index.yaml | |
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/${version}.tgz gs://helm.coder.com/logstream-kube | |
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/logstream-kube | |
- name: Create and upload release | |
run: | | |
set -euo pipefail | |
version=${{ steps.version.outputs.version }} | |
# check if release already exists and match the version | |
if [[ $(gh release view $version --json name -q '.name' | cat) == $version ]]; then | |
echo "Release $version already exists" | |
exit 0 | |
fi | |
echo "Creating release $version" | |
# if version contains -rc, publish as a pre-release and don't set as latest | |
if [[ $version == *-rc* ]]; then | |
gh release create $version -t $version --generate-notes --prerelease --latest=false --verify-tag build/${version}.tgz#helm.tar.gz | |
else | |
gh release create $version -t $version --generate-notes --verify-tag build/${version}.tgz#helm.tar.gz | |
fi | |
env: | |
GITHUB_TOKEN: ${{ github.token }} |