Skip to content

Commit

Permalink
ci(fix): run CI jobs on tags too (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
  • Loading branch information
hairyhenderson authored Jun 9, 2024
1 parent 1565e72 commit 4432450
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

Expand Down
39 changes: 16 additions & 23 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Docker Build
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

Expand Down Expand Up @@ -32,55 +33,47 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.12.1
version: latest
driver-opts: |
image=moby/buildkit:buildx-stable-1
network=host
- name: determine if this is a tag
run: |
if (git describe --abbrev=0 --exact-match &>/dev/null); then
tag=$(git describe --abbrev=0 --exact-match)
echo "is_tag=true" >> $GITHUB_ENV
echo "git_tag=$tag" >> $GITHUB_ENV
# splits the major version from $tag - assumes it's a 3-part semver
echo "major_version=${tag%%\.*}" >> $GITHUB_ENV
fi
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter'
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || env.is_tag == 'true')
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: hairyhenderson
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || env.is_tag == 'true')
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
- name: Build & Push (non-main branch)
run: |
set -ex
make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=localhost:5000/${IMG_NAME} BUILDX_ACTION=--push
make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=localhost:5000/${{ github.repository }} BUILDX_ACTION=--push
docker buildx imagetools create --dry-run -t localhost:5000/${IMG_NAME}:dev localhost:5000/${IMG_NAME}:latest
docker buildx imagetools create --dry-run -t localhost:5000/${IMG_NAME}:dev-alpine localhost:5000/${IMG_NAME}:alpine
docker buildx imagetools create --dry-run -t localhost:5000/${{ github.repository }}:dev localhost:5000/${{ github.repository }}:latest
docker buildx imagetools create --dry-run -t localhost:5000/${{ github.repository }}:dev-alpine localhost:5000/${{ github.repository }}:alpine
if: github.repository != 'hairyhenderson/sagemcom_fast_exporter' || github.ref != 'refs/heads/main'
- name: Build & Push (main/tags)
run: |
src_repo=hairyhenderson/${IMG_NAME}
src_repo=${{ github.repository}}
set -x
make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=${src_repo} BUILDX_ACTION=--push
set -x
docker buildx imagetools create -t ghcr.io/hairyhenderson/${IMG_NAME}:latest ${src_repo}:latest
docker buildx imagetools create -t ghcr.io/hairyhenderson/${IMG_NAME}:alpine ${src_repo}:alpine
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || env.is_tag == 'true')
docker buildx imagetools create -t ghcr.io/${src_repo}:latest ${src_repo}:latest
docker buildx imagetools create -t ghcr.io/${src_repo}:alpine ${src_repo}:alpine
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
- name: Push (tagged release)
run: |
src_repo=hairyhenderson/${IMG_NAME}
src_repo=${{ github.repository }}
git_tag=${{ github.ref_name }}
major_version=${git_tag%%\.*}
set -x
repo=$src_repo
Expand All @@ -89,9 +82,9 @@ jobs:
docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${src_repo}:alpine
docker buildx imagetools create -t ${repo}:${major_version}-alpine ${src_repo}:alpine
repo=ghcr.io/hairyhenderson/${IMG_NAME}
repo=ghcr.io/${{ github.repository }}
docker buildx imagetools create -t ${repo}:${git_tag} ${src_repo}:latest
docker buildx imagetools create -t ${repo}:${major_version} ${src_repo}:latest
docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${src_repo}:alpine
docker buildx imagetools create -t ${repo}:${major_version}-alpine ${src_repo}:alpine
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && env.is_tag == 'true'
if: github.repository == 'hairyhenderson/sagemcom_fast_exporter' && startsWith(github.ref, 'refs/tags/')

0 comments on commit 4432450

Please sign in to comment.