Merge pull request #7 from PartTimeLegend/renovate/actions-checkout-4.x #5
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 and Publish Docker Image | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
env: | |
BUILD_DATE: ${{ github.event.head_commit.timestamp }} | |
IMAGE_NAME: hammy-mchamilton | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 # Check out your repository's code | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate build number tag | |
id: generate_tag | |
run: echo ::set-output name=tag::${GITHUB_RUN_NUMBER} | |
- name: Convert repository owner to lowercase | |
run: echo "::set-env name=REPOSITORY_OWNER::${{ github.repository_owner.lowercase }}" | |
- name: Build the Docker image | |
run: docker build --file Dockerfile --tag ghcr.io/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.tag }} --tag ghcr.io/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}:latest --build-arg BUILD_DATE=${BUILD_DATE} . | |
- name: Push the Docker image to GitHub Container Registry | |
run: docker push ghcr.io/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.tag }} && docker push ghcr.io/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}:latest |