Skip to content

Commit

Permalink
GitHub: Rework release action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gacko committed Jul 30, 2024
1 parent 3f37d25 commit 582f637
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Releases

on:
push:
branches:
- main
- master
# Remove when ready.
- liljx
paths:
- "*/v*.*.*"
# Remove when ready.
- .github/workflows/releases.yaml

jobs:
get-releases:
name: Get releases
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get releases
id: get-releases
run: echo releases="$(jq --null-input --args '$ARGS.positional' --compact-output -- {azure,capa}/v*.*.*)" >> "${GITHUB_OUTPUT}"

outputs:
releases: ${{ steps.get-releases.outputs.releases }}

create-release:
name: Create release
runs-on: ubuntu-latest
needs: get-releases

strategy:
matrix:
release: ${{ fromJSON(needs.get-releases.outputs.releases) }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get provider & version
id: get-provider-version
env:
release: ${{ matrix.release }}
run: |
# Get provider & version.
provider="${release%/v*.*.*}"
version="${release#${provider}/}"
# Map provider.
case "${provider}" in
capa)
provider="aws"
;;
esac
# Store provider & version.
echo provider="${provider}" >> "${GITHUB_OUTPUT}"
echo version="${version}" >> "${GITHUB_OUTPUT}"
- name: Get release
id: get-release
env:
GH_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
provider: ${{ steps.get-provider-version.outputs.provider }}
version: ${{ steps.get-provider-version.outputs.version }}
run: |
# Define tag.
tag="${provider}/${version}"
# Check release.
[ "$(gh release view "${tag}" --json id)" ] && exists=true || exists=false
# Store tag & exists.
echo tag="${tag}" >> "${GITHUB_OUTPUT}"
echo exists="${exists}" >> "${GITHUB_OUTPUT}"
- name: Create release
# if: ${{ ! steps.get-release.outputs.exists }}
env:
GH_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
release: ${{ matrix.release }}
provider: ${{ steps.get-provider-version.outputs.provider }}
version: ${{ steps.get-provider-version.outputs.version }}
tag: ${{ steps.get-release.outputs.tag }}
exists: ${{ steps.get-release.outputs.exists }}
run: |
# Define title, notes & files.
title="Workload cluster release ${version} for ${provider}"
notes="This release was automatically created by GitHub Actions."
files=("${release}/release.yaml")
# Determine pre-release.
[[ "${version}" == v*.*.*-* ]] && prerelease="--prerelease" || prerelease=""
# Create release.
echo gh release create "${tag}" --title "${title}" --notes "${notes}" ${files[@]} ${prerelease} --target "${GITHUB_REF_NAME}"

0 comments on commit 582f637

Please sign in to comment.