Factor out pre commit workflow using composite action #13
Workflow file for this run
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
on: | |
pull_request: | |
branches: [main, master] | |
push: | |
branches: [main, master] | |
release: | |
types: [published] | |
name: docker-build | |
jobs: | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup variables | |
run: | | |
echo "IMAGE_TAG=$(if [ ${{ github.ref_name }} == master ]; then echo latest; elif [ ${{ github.event_name }} == release ]; then echo ${{ github.ref_name }}; else echo staging; fi)" >> $GITHUB_ENV | |
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
echo "PUSH_IMAGE=$(if [ ${{ github.event_name }} != pull_request ]; then echo true; else echo false; fi)" >> $GITHUB_ENV | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: ${{ env.PUSH_IMAGE }} | |
tags: ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
provenance: false | |
build-args: | | |
VCS_NAME=${{ github.repository }} | |
VCS_URL=${{ github.server_url}}/${{ github.repository }} | |
VCS_REF=${{ github.sha }} | |
VCS_REF_SHORT=${{ env.SHA_SHORT }} | |
VCS_VER=${{ github.ref_name }} | |
VCS_ID=${{ github.repository_id }} | |
VCS_NAMESPACE=${{ github.repository_owner }} |