Skip to content

GHA Add publish and release process to Spacelift (#37) #5

GHA Add publish and release process to Spacelift (#37)

GHA Add publish and release process to Spacelift (#37) #5

Workflow file for this run

# Terraform Provider release workflow.
name: Release
# This GitHub action creates a release when a tag that matches the pattern
# "v*" (e.g. v0.1.0) is created.
on:
push:
tags:
- 'v*'
# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 # v5.2.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
args: release --clean
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- name: Release new version to spacelift
if: startsWith(github.ref, 'refs/tags/')
env:
GPG_KEY_ID: ${{ steps.import_gpg.outputs.keyid }}
SPACELIFT_API_KEY_ENDPOINT: https://spacelift.ktl.net
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
run:
spacectl provider create-version --type=splitpolicies
- name: Publish provider
if: startsWith(github.ref, 'refs/tags/')
env:
GPG_KEY_ID: ${{ steps.import_gpg.outputs.keyid }}
SPACELIFT_API_KEY_ENDPOINT: https://spacelift.ktl.net
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
run: |
spacectl provider list-versions --type splitpolicies -o json > versions.json
VERSION_NUMBER=${{ github.ref_name }}
VERSION_ID=$(jq -r --arg version "${VERSION_NUMBER#v}" '.versions[] | select(.number == $version) | .id' versions.json)
echo "Publishing ID: $VERSION_ID"
spacectl provider publish-version --version=$VERSION_ID