Add GH action #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: Push image | |
on: | |
schedule: | |
# Rebuild once a week | |
- cron: '0 0 * * 0' | |
push: | |
branches: [ main ] | |
# Allow running this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout image repo | |
uses: actions/checkout@v3 | |
- name: Checkout upstream repo | |
uses: actions/checkout@v3 | |
with: | |
repository: mailhog/mailhog | |
token: ${{ secrets.GITHUB_TOKEN }} | |
path: upstream | |
# We're only interested in the tags, so check them out, too (not just a single commit) | |
fetch-depth: 0 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create tags | |
id: create-tag | |
run: | | |
# Find latest tag | |
cd upstream | |
VERSION="$(git describe --tags $(git rev-list --tags --max-count=1))" | |
VERSION_DATE="$VERSION-$(date +'%Y-%m-%d')" | |
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/mailhog | |
TAGS="${GHCR_IMAGE}:latest,${GHCR_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION_DATE}" | |
echo "TAGS=${TAGS}" | tee -a $GITHUB_ENV | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.TAGS }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
org.opencontainers.image.revision=${{ env.GIT_SHA }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA}} and ref ${{ env.GIT_REF }} | |