Add version check step for tag-triggered runs #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" | |
on: | |
push: | |
branches: | |
- "main" | |
tags: | |
- "[0-9]+.[0-9]+.[0-9]+*" | |
jobs: | |
build: | |
name: "Build" | |
runs-on: "ubuntu-latest" | |
permissions: | |
packages: "write" | |
env: | |
# GitHub Actions expressions conditionals are ternary expressions that | |
# look a lot like bash. In Python, this would read as: | |
# | |
# github.ref_name if github.ref_type == 'tag' else 'latest' | |
# | |
# https://docs.github.com/en/actions/learn-github-actions/expressions | |
IMAGE_TAG: "${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}" | |
steps: | |
- uses: "actions/checkout@v3" | |
- name: "Check version" | |
if: "github.ref_type == 'tag'" | |
run: | | |
source .env | |
test ${{ github.ref_name }} = ${VERSION} | |
- name: "Build" | |
run: "docker compose build" | |
- name: "GHCR login" | |
uses: "docker/login-action@v2" | |
with: | |
registry: "ghcr.io" | |
username: "${{ github.repository_owner }}" | |
password: "${{ secrets.GITHUB_TOKEN }}" | |
- name: "Push to image registry" | |
run: "docker compose push" |