From 153235b9042fde3ca5c56e975053fc504f28665d Mon Sep 17 00:00:00 2001 From: Ryan Shatford Date: Tue, 16 Apr 2024 08:11:26 -0700 Subject: [PATCH] Update GH build workflow with manual trigger --- .github/workflows/build.yml | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..1b6e5dc1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Create and publish a Docker image + +on: + push: + branches: [ 'release', 'releases/**'] + workflow_dispatch: + inputs: + branch: + description: 'Branch to build' + required: true + default: 'main' + +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 + with: + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }} + + # login-action v3.1.0 + - name: Log in to the Container registry + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # metadata-action v5.5.1 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # In order to support deploying multiple versions that don't stomp on + # each other some new tagging rules are created. + # The tagging below follows: + # - When a properly formatted tag is created, as in a release, put the semver version x.y.z in the tag + # - If a build is triggered manually, then mark the branch and short sha in the tag + # - When the default branch is updated, create a release candiate tag + tags: | + type=semver,pattern={{version}} + type=sha,prefix={{branch || tag}}-{{sha}},event=workflow_dispatch + type=raw,value={{date 'YYYYMMDD-HHmm' tz='America/Los_Angeles'}}-rc,event=branch,branch={{is_default_branch}} + + # build-push-action v5.3.0 + - name: Build and push Docker image + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}