Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GitHub Actions #329

Closed
100 changes: 0 additions & 100 deletions .github/workflows/ci.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/helm-release.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/helm-test.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/push-image-ghcr.yml

This file was deleted.

104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Release

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To note, I removed the preceding v for better flexibility in the jobs. This way, in the downstream jobs you can manually prefix where applicable rather than assume it will be everywhere (which it isn't e.g. Docker image tags).


jobs:
github:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Version ${{ github.ref_name }}
draft: false
prerelease: false

docker-hub:
needs: github
runs-on: ubuntu-latest
env:
IMAGE: danihodovic/celery-exporter
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare Image Metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE }}
ghcr.io/${{ env.IMAGE }}
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login To Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
Comment on lines +49 to +50
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to set DOCKER_HUB_USERNAME and DOCKER_HUB_TOKEN as GitHub Actions secrets.

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build, tag, and push image to Docker Hub
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
platforms: linux/amd64,linux/arm64
push: true
annotations: ${{ steps.metadata.outputs.annotations }}
labels: ${{ steps.metadata.outputs.labels }}
tags: ${{ steps.metadata.outputs.tags }}
- name: Update Description On Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
repository: ${{ env.IMAGE }}
Comment on lines +68 to +73
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automates the overview on Docker Hub, which is currently empty ...

Screenshot 2024-10-16 at 20 40 46


helm-chart:
runs-on: ubuntu-latest
needs: github
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Set Up Helm
uses: azure/[email protected]
with:
version: v3.14.4
- name: Get Chart Version
id: chart-version
run: echo "::set-output name=version::$(grep 'version:' ./charts/celery-exporter/Chart.yaml | cut -d ' ' -f 2)"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic test that this works ...

$ ls -l ./charts/* 
total 24
-rw-r--r--   1 Kingori  staff   333 Oct 17 04:22 Chart.yaml
-rw-r--r--   1 Kingori  staff  2790 Oct 16 18:57 README.md
drwxr-xr-x   3 Kingori  staff    96 Oct 16 18:57 ci
drwxr-xr-x  10 Kingori  staff   320 Oct 16 18:57 templates
-rw-r--r--   1 Kingori  staff  2640 Oct 16 18:57 values.yaml

$ grep 'version:' ./charts/celery-exporter/Chart.yaml | cut -d ' ' -f 2
0.7.0

- name: Package Helm chart
run: helm package ./charts/celery-exporter --app-version=${{ github.ref_name }}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local test that this works ...

$ helm package ./charts/celery-exporter --app-version=0.10.13          
Successfully packaged chart and saved it to: /Users/Kingori/Repositories/itskingori/celery-exporter/celery-exporter-0.7.0.tgz

- name: Upload To Github Release
uses: softprops/action-gh-release@v2
with:
files: |
celery-exporter-${{ steps.chart-version.outputs.version }}.tgz
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be available after packaging ...

$ helm package ./charts/celery-exporter --app-version=0.10.13          
Successfully packaged chart and saved it to: /Users/Kingori/Repositories/itskingori/celery-exporter/celery-exporter-0.7.0.tgz

$ ls -l celery-exporter-0.7.0.tgz 
-rw-r--r--  1 Kingori  staff  4981 Oct 17 04:53 celery-exporter-0.7.0.tgz

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +93 to +104
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a release for the Helm Chart like this ...

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_RELEASE_NAME_TEMPLATE: "{{ .Name }}-chart-{{ .Version }}"

Have it uploaded as an asset to the GitHub release (on tag), because each time we tag we'll get two releases which can be cleaner, here's what we have now ...

Screenshot 2024-10-17 at 04 50 49

Loading