ci: auto detect if released OS images should be marked as "latest"

This commit is contained in:
Malte Poll 2023-01-11 11:40:27 +01:00 committed by Malte Poll
parent 77d921824e
commit 5ba1b6780b

View File

@ -13,6 +13,10 @@ on:
type: boolean type: boolean
default: false default: false
env:
REPO: edgelesssys/constellation
TAG: ${{ github.event.release.tag_name }}${{ github.event.inputs.tag }}
jobs: jobs:
update: update:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
@ -25,6 +29,28 @@ jobs:
with: with:
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }} ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
- name: Override latest
id: override
if: github.event.inputs.latest == 'true'
run: echo "LATEST=true" >> "$GITHUB_ENV"
- name: Check if should mark latest
if: github.event.inputs.latest != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
latest_release_tag=$(gh api \
-H "Accept: application/vnd.github+json" \
"/repos/${REPO}/releases/latest" \
| jq -r '.tag_name')
echo "Latest release tag: ${latest_release_tag}"
echo "Current tag: ${TAG}"
if [[ "${latest_release_tag}" == "${TAG}" ]]; then
echo "LATEST=true" >> "$GITHUB_ENV"
else
echo "LATEST=false" >> "$GITHUB_ENV"
fi
- name: Setup Go environment - name: Setup Go environment
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with: with:
@ -44,9 +70,9 @@ jobs:
- name: Add version to versionsapi - name: Add version to versionsapi
working-directory: internal/versionsapi/cli working-directory: internal/versionsapi/cli
run: | run: |
latest=$([[ "${{ inputs.latest }}" = "true" ]] && echo "--latest" || echo "") latest_flag=$([[ "${LATEST}" = "true" ]] && echo "--latest" || echo "")
./versionsapi add \ ./versionsapi add \
--release \ --release \
--stream "stable" \ --stream "stable" \
--version "${{ github.event.release.tag_name }}${{ github.event.inputs.tag }}" \ --version "${TAG}" \
"${latest}" "${latest_flag}"