-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
--- | ||
# Release Service 'Called workflow' | ||
# Publishes Neu.ro service as ghcr.io Docker image and Helm Chart, | ||
# Create a github release with linked issues and pull requests | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
image: | ||
description: short image name without repo/owner and tag, e.g. platformstorageapi | ||
required: true | ||
type: string | ||
helm-charts: | ||
description: A space-separated list of helm charts | ||
required: true | ||
type: string | ||
artifact: | ||
description: The artifact name uploaded by upload-image-action | ||
required: false | ||
default: image | ||
type: string | ||
outputs: | ||
version: | ||
description: Version | ||
value: ${{ jobs.release.outputs.version }} | ||
skip: | ||
description: Skip | ||
value: ${{ jobs.release.outputs.skip }} | ||
tag: | ||
description: Tag | ||
value: ${{ jobs.release.outputs.tag }} | ||
prerelease: | ||
description: Prerelease | ||
value: ${{ jobs.release.outputs.prerelease }} | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
release: | ||
name: Release image and heml chart | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.meta.outputs.version }} | ||
skip: ${{ steps.meta.outputs.skip }} | ||
tag: ${{ steps.meta.outputs.tag }} | ||
prerelease: ${{ steps.meta.outputs.prerelease }} | ||
steps: | ||
- name: Checkout commit | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Detect metadata | ||
id: meta | ||
run: | | ||
import re | ||
import sys | ||
def dump(val): | ||
if val: | ||
return "true" | ||
else: | ||
return "" | ||
ref = "${{ github.ref }}" | ||
PRE = "refs/tags/" | ||
if not ref.startswith(PRE): | ||
print(f"::error:: Ref {ref} doesn't contain a tag") | ||
sys.exit(1) | ||
else: | ||
tag = ref[len(PRE):] | ||
match = re.match(r"^v\d+\.\d+(\.\d+)?(?P<pre>(a|b|rc)\d*)?$", tag) | ||
if not match: | ||
print( | ||
f"::error:: Invalid tag {tag}; ", | ||
"The tag should have vYY.MM[.NN][{a|b|rc}N] format ", | ||
"where YY is the current year, MM is the current month, " | ||
"NN is incremental number, " | ||
"every next month resets the number to 0, " | ||
"a -- alpha, b -- beta, rc -- release candidate, N -- number.", | ||
) | ||
sys.exit(1) | ||
else: | ||
print(f"::set-output name=tag::{tag}") | ||
version = tag[1:] | ||
print(f"::set-output name=version::{version}") | ||
print(f"::set-output name=prerelease::{dump(match.group('pre'))}") | ||
shell: python | ||
- name: Install Helm | ||
uses: azure/[email protected] | ||
with: | ||
version: v3.7.0 | ||
- name: Purge old artifacts | ||
uses: kolpav/purge-artifacts-action@v1 | ||
with: | ||
token: ${{ github.token }} | ||
expire-in: 30mins | ||
- name: Download image artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: ${{ inputs.artifact }} | ||
- name: Login to ghcr.io | ||
uses: docker/[email protected] | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
- name: Load image into docker | ||
run: | | ||
docker load --input ${{ inputs.image }}.tar | ||
shell: bash | ||
- name: Tag remote latest image | ||
run: | | ||
docker tag ${{ inputs.image }}:latest ghcr.io/neuro-inc/${{ inputs.image }}:latest | ||
shell: bash | ||
- name: Tag remote versioned image | ||
run: | | ||
docker tag ${{ inputs.image }}:latest ghcr.io/neuro-inc/${{ inputs.image }}:${{ steps.meta.outputs.version }} | ||
shell: bash | ||
- name: Push latest image to ghcr.io | ||
run: | | ||
docker push ghcr.io/neuro-inc/${{ inputs.image }}:latest | ||
shell: bash | ||
- name: Push versioned image to ghcr.io | ||
run: | | ||
docker push ghcr.io/neuro-inc/${{ inputs.image }}:${{ steps.meta.outputs.version }} | ||
shell: bash | ||
- name: Create chart | ||
run: | | ||
for HELM_CHART in ${{ inputs.helm_charts }}; do | ||
VALUES=$$(cat charts/${HELM_CHART}/values.yaml | envsubst) | ||
echo "$$VALUES" > charts/${HELM_CHART}/values.yaml | ||
CHART=$$(cat charts/${HELM_CHART}/Chart.yaml | envsubst) | ||
echo "$$CHART" > charts/${HELM_CHART}/Chart.yaml | ||
done | ||
env: | ||
IMAGE_REPO: ghcr.io/neuro-inc/${{ inputs.image }} | ||
IMAGE_TAG: ${{ steps.meta.outputs.version }} | ||
CHART_VERSION: ${{ steps.meta.outputs.version }} | ||
APP_VERSION: ${{ steps.meta.outputs.version }} | ||
shell: bash | ||
- name: Release chart | ||
env: | ||
HELM_EXPERIMENTAL_OCI: '1' | ||
CR_TOKEN: ${{ github.token }} | ||
run: | | ||
echo $CR_TOKEN | helm registry login ghcr.io -u x-access-token --password-stdin | ||
for HELM_CHART in ${{ inputs.helm_charts }}; do | ||
helm package charts/${HELM_CHART} -u | ||
helm push ${HELM_CHART}-${{ steps.meta.outputs.version }}.tgz oci://ghcr.io/neuro-inc/helm-charts | ||
done | ||
shell: bash | ||
- name: GitHub Release | ||
uses: ncipollo/[email protected] | ||
with: | ||
name: ${{ steps.meta.outputs.version }} | ||
prerelease: ${{ steps.meta.outputs.prerelease }} | ||
generateReleaseNotes: 'true' | ||
tag: ${{ steps.meta.outputs.tag }} | ||
token: ${{ github.token }} |