Skip to content

Merge pull request #2 from mchro/patch-1 #14

Merge pull request #2 from mchro/patch-1

Merge pull request #2 from mchro/patch-1 #14

---
name: Create and publish a Docker image
on:
push:
branches: ['master']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Fetch the version from Cargo.toml
id: retrieve_tag
run: |
echo ::set-output name=crate-tag::$(cat Cargo.toml | grep version | head -n1 | awk '{ print $3 }' | tr -d '"')
echo ::set-output name=image_registry::$(echo '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}' | tr '[:upper:]' '[:lower:]')
shell: bash
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.retrieve_tag.outputs.image_registry }}:${{ steps.retrieve_tag.outputs.crate-tag }}
labels: ${{ steps.meta.outputs.labels }}