Skip to content

Switch to tagged version for GitHub Action (#141) #249

Switch to tagged version for GitHub Action (#141)

Switch to tagged version for GitHub Action (#141) #249

Workflow file for this run

---
name: Docker
"on":
push:
branches:
- main
pull_request:
jobs:
build:
name: Build and push
runs-on: ubuntu-latest
strategy:
matrix:
dockerfile:
- Dockerfile.rust
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get image name from Dockerfile name
id: name
run: |
image_name=$(echo ${{ matrix.dockerfile }} | cut -d '.' -f 2)
echo "image_name=$image_name" >> $GITHUB_OUTPUT
echo "$image_name"
- name: Collect metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ steps.name.outputs.image_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: ${{ matrix.dockerfile }}
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}