Release #49
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
name: Release | |
on: | |
push: | |
branches: | |
- main | |
- '*-test' | |
- '*-dev' | |
- '*-fix' | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
id-token: write | |
steps: | |
- name: Cancel Previous Runs | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set Environment | |
id: set-env | |
run: | | |
BRANCH=${GITHUB_REF#refs/heads/} | |
if [[ "$BRANCH" =~ .*-(test|dev|fix)$ ]]; then | |
echo "Using test environment" | |
echo "env_type=test" >> $GITHUB_OUTPUT | |
echo "tag_suffix=-${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT | |
echo "branch_name=${BRANCH}" >> $GITHUB_OUTPUT | |
echo "is_prerelease=true" >> $GITHUB_OUTPUT | |
echo "fetch_binaries=0" >> $GITHUB_OUTPUT | |
echo "install_shell_utils=0" >> $GITHUB_OUTPUT | |
else | |
echo "Using production environment" | |
echo "env_type=prod" >> $GITHUB_OUTPUT | |
echo "tag_suffix=" >> $GITHUB_OUTPUT | |
echo "branch_name=latest" >> $GITHUB_OUTPUT | |
echo "is_prerelease=false" >> $GITHUB_OUTPUT | |
echo "fetch_binaries=1" >> $GITHUB_OUTPUT | |
echo "install_shell_utils=1" >> $GITHUB_OUTPUT | |
fi | |
- name: Generate version | |
id: generate-version | |
run: | | |
# Get current date and format it as YYYY.MM | |
CURRENT_DATE=$(date +%Y.%m) | |
# Get branch-specific suffix | |
SUFFIX="${{ steps.set-env.outputs.tag_suffix }}" | |
# Get latest tag matching the current type (with or without suffix) | |
if [ -n "$SUFFIX" ]; then | |
# Per branch di test/dev/fix, cerca tag che finiscono con lo stesso suffisso | |
LATEST_TAG=$(git tag --sort=-version:refname | grep -E "v[0-9]+\.[0-9]+\.[0-9]+${SUFFIX}$" | head -n1 || echo "v0.0.0${SUFFIX}") | |
else | |
# Per main, cerca solo tag senza suffisso | |
LATEST_TAG=$(git tag --sort=-version:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -n1 || echo "v0.0.0") | |
fi | |
echo "Latest matching tag: $LATEST_TAG" | |
# Extract release number, removing any suffix | |
LATEST_RELEASE_NUMBER=$(echo "$LATEST_TAG" | sed -E 's/v[0-9]+\.[0-9]+\.([0-9]+).*/\1/') | |
# Increment release number if same month, otherwise reset to 0 | |
if [[ "$(date +%Y.%m)" == "$(echo "$LATEST_TAG" | cut -d '.' -f 1,2 | cut -d 'v' -f 2)" ]]; then | |
RELEASE_NUMBER=$((LATEST_RELEASE_NUMBER + 1)) | |
else | |
RELEASE_NUMBER=0 | |
fi | |
# Set VERSION environment variable | |
VERSION="v$CURRENT_DATE.$RELEASE_NUMBER$SUFFIX" | |
echo "Generated version: $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
# Update Chart.yaml with new version | |
sed -i "s/^version:.*$/version: ${VERSION#v}/" charts/batbelt/Chart.yaml | |
sed -i "s/^appVersion:.*$/appVersion: \"${VERSION#v}\"/" charts/batbelt/Chart.yaml | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get Packages and plugins to install | |
id: file-content | |
run: | | |
ENV_TYPE="${{ steps.set-env.outputs.env_type }}" | |
PACKAGES="$(cat env/${ENV_TYPE}/packagelist.txt|xargs)" | |
KREWPLUGINS="$(cat env/${ENV_TYPE}/krewplugins.txt|xargs)" | |
PLATFORMS="$(cat env/${ENV_TYPE}/platforms.txt|xargs|sed -e 's/ /,/g')" | |
echo "packages=${PACKAGES}" >> $GITHUB_OUTPUT | |
echo "krewplugins=${KREWPLUGINS}" >> $GITHUB_OUTPUT | |
echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT | |
echo "Debug: Using environment: ${ENV_TYPE}" | |
echo "Debug: Packages to install: ${PACKAGES}" | |
echo "Debug: Platforms to build: ${PLATFORMS}" | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ env.VERSION }} | |
ghcr.io/${{ github.repository }}:${{ steps.set-env.outputs.branch_name }} | |
platforms: ${{ steps.file-content.outputs.platforms }} | |
build-args: | | |
PACKAGES=${{ steps.file-content.outputs.packages }} | |
KREWPLUGINS=${{ steps.file-content.outputs.krewplugins }} | |
FETCH_BINARIES=${{ steps.set-env.outputs.fetch_binaries }} | |
INSTALL_SHELL_UTILS=${{ steps.set-env.outputs.install_shell_utils }} | |
cache-from: | | |
type=registry,ref=ghcr.io/${{ github.repository }}:buildcache${{ steps.set-env.outputs.tag_suffix }} | |
type=registry,ref=ghcr.io/${{ github.repository }}:${{ steps.set-env.outputs.branch_name }} | |
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache${{ steps.set-env.outputs.tag_suffix }},mode=max | |
- name: Generate Package Report | |
id: package-report | |
run: | | |
chmod +x build/generate_package_report.sh | |
./build/generate_package_report.sh \ | |
"${{ github.repository }}" \ | |
"${{ env.VERSION }}" \ | |
"PACKAGES.md" \ | |
"package_report.md" \ | |
"${{ steps.set-env.outputs.env_type }}" | |
- name: Update Documentation | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add PACKAGES.md | |
git commit -m "docs: update packages list for version ${{ env.VERSION }}" || echo "No changes to commit" | |
git push | |
- name: Create Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ env.VERSION }} | |
name: Release ${{ env.VERSION }} | |
body_path: package_report.md | |
prerelease: ${{ steps.set-env.outputs.is_prerelease }} |