Better actions #4
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: Build and Push Docker Image on Add/Remove | |
on: | |
push: | |
# triggers only when a file has been changed, not the contents | |
paths: | |
- '**' | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-buildx-action@v3 | |
- uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Lowercase the repo name | |
run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Generate semantic version | |
id: semver | |
run: | | |
sleep 10 | |
RUN_NUMBER=${GITHUB_RUN_NUMBER} | |
MAJOR=$((RUN_NUMBER / 100)) | |
MINOR=$(((RUN_NUMBER % 100) / 10)) | |
PATCH=$((RUN_NUMBER % 10)) | |
VERSION="$MAJOR.$MINOR.$PATCH" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
echo "Calculated version: $VERSION (from run #$RUN_NUMBER)" | |
- uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.REPO_LC }}:latest | |
# Doesnt need a whole new version with a spelling update or something of the sorts | |
${{ env.REPO_LC }}:${{ env.VERSION }} | |
${{ env.REPO_LC }}:${{ env.VERSION }}-${{ github.sha }} |