Release #40
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 | |
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 | |
fi | |
- name: Generate version | |
id: generate-version | |
run: | | |
# Get current date and format it as YYYY.MM | |
CURRENT_DATE=$(date +%Y.%m) | |
# Get latest tag and extract release number | |
LATEST_TAG=$(git describe --tags --abbrev=0 --match "v[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "v0.0.0") | |
LATEST_RELEASE_NUMBER=$(echo "$LATEST_TAG" | cut -d '.' -f 3 | cut -d 'v' -f 2) | |
# 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${{ steps.set-env.outputs.tag_suffix }}" | |
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 }} | |
SKIP_SHELL_UTILS=${{ steps.set-env.outputs.env_type != 'prod' }} | |
SKIP_FETCH_BINARIES=${{ steps.set-env.outputs.env_type != 'prod' }} | |
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 }} |