Skip to content

release

release #8

Workflow file for this run

#
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.
#
name: release
on:
workflow_dispatch:
inputs:
ReleaseType:
type: choice
description: Select the version to released
options:
- Major Version
- Minor Version
- Patch Version
env:
BOT_USER_NAME: eclipse-xpanse-bot
BOT_EMAIL_ID: xpanse-bot@eclipse.org
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
pre-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
- name: Set current version env variable
id: version
run: |
echo "CurrentVersion=$(sed -n 's/^.*version.*= *"\([a-z0-9.]*\)"/\1/pg' version.go)" >> $GITHUB_OUTPUT
if [ "${{github.event.inputs.ReleaseType}}" = "Major Version" ]; then
echo "VersionFragment=major" >> $GITHUB_ENV
elif [ "${{github.event.inputs.ReleaseType}}" = "Minor Version" ]; then
echo "VersionFragment=feature" >> $GITHUB_ENV
elif [ "${{github.event.inputs.ReleaseType}}" = "Patch Version" ]; then
echo "VersionFragment=bug" >> $GITHUB_ENV
else
echo "No matching feature type found"
fi
- name: Set next development version environment variable
id: new_version
uses: christian-draeger/increment-semantic-version@1.1.0
with:
current-version: ${{ steps.version.outputs.CurrentVersion }}
version-fragment: ${{ env.VersionFragment }}
- name: Update version
run: |
sed -i 's/\(^.*version.*= *"\)\([a-z0-9.]*\)"/\1${{ steps.new_version.outputs.next-version }}"/g' version.go
- uses: EndBug/add-and-commit@v9
with:
message: Release v${{ steps.new_version.outputs.next-version }}
committer_name: ${{ env.BOT_USER_NAME }}
committer_email: ${{ env.BOT_EMAIL_ID }}
- name: Create a GitHub tag
# This action here is only target for creating a tag, but it also created a simple github release which will be rewritten by the following goreleaser job.
# That may gain a little benefit in case the goreleaser job failed. Anyway, it should be replaced by some other actions which creating tags only.
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.new_version.outputs.next-version }}
name: v${{ steps.new_version.outputs.next-version }}
outputs:
current_version: ${{ steps.version.outputs.CurrentVersion }}
release_version: v${{ steps.new_version.outputs.next-version }}
docker-releaser:
needs: pre-release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.pre-release.outputs.release_version }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ">=1.21"
- name: Build policy-man
run: make build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.BOT_USER_NAME }}
password: ${{ secrets.BOT_GITHUB_DOCKER_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build Docker Image and Push
uses: docker/build-push-action@v6.9.0
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.pre-release.outputs.release_version }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
goreleaser:
runs-on: ubuntu-latest
needs: pre-release
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.pre-release.outputs.release_version }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ">=1.21"
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.ORG_GPG_PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}