feat: initial commit #1
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: # yamllint disable-line rule:truthy | |
pull_request: | |
push: | |
branches: | |
- main | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
jobs: | |
publish-image: | |
name: Publish image | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
permissions: | |
contents: read | |
id-token: write | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build list of Docker tags to use | |
id: tag-types | |
run: | | |
if [[ ${{ contains(github.ref, 'tag') }} == true ]]; then | |
TAGS=" | |
type=semver,pattern={{major}},priority=920 | |
type=semver,pattern={{major}}.{{minor}},priority=910 | |
type=semver,pattern={{version}},priority=900 | |
type=ref,event=branch | |
type=sha,format=long" | |
else | |
TAGS=" | |
type=ref,event=branch | |
type=sha,format=long" | |
fi | |
# https://trstringer.com/github-actions-multiline-strings | |
{ | |
echo "TAGS<<EOF" | |
echo "$TAGS" | |
echo "EOF" | |
} >> "$GITHUB_ENV" | |
- name: Set Docker labels and tags | |
id: metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
flavor: | | |
latest=${{ github.ref == 'refs/heads/main' }} | |
tags: ${{ env.TAGS }} | |
- name: Login to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get latest git tag | |
id: get-tag | |
uses: olegtarasov/get-tag@2.1.3 | |
- name: Build and push Docker image | |
id: build-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
build-args: | | |
VERSION=${{ steps.get-tag.outputs.tag }} | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} |