Skip to content

Commit

Permalink
ci: Run Docker publish workflow on a schedule (meltano#6570)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillDaSilva committed Aug 9, 2022
1 parent 6ad4081 commit cdddf54
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: Docker Publish

# This workflow will build and publish all public Docker images to the configured registry.
# Set the input `dry-run` to `false` to skip pushing images to the registry.
# Set the input `dry_run` to `false` to skip pushing images to the registry.

on:
schedule:
# Weekly on Sunday at 04:45 UTC
- cron: '45 4 * * 0'
workflow_dispatch:
inputs:
dry-run:
dry_run:
description: "Dry run (skip push step)"
type: boolean
required: true
Expand All @@ -20,12 +23,8 @@ on:
- docker.io

jobs:
public_docker_build:
build_meltano_image:
runs-on: ubuntu-latest
env:
# Boolean values don't actually work so cast to 'true' and 'false'
# https://github.com/actions/runner/issues/1483
DRY_RUN_STR: ${{ format('{0}', github.event.inputs.dry-run) || 'true' }}

strategy:
fail-fast: false
Expand All @@ -41,6 +40,18 @@ jobs:
is-default-python: false

steps:
- name: Set the workflow inputs
# This step makes it so that the same workflow inputs can be accessed
# regardless of what event triggered it.
env:
DEFAULT_DRY_RUN: "true"
DEFAULT_REGISTRY: "ghcr.io"
run: |
# Boolean values don't actually work so cast to 'true' and 'false'
# https://github.com/actions/runner/issues/1483
echo "dry_run=${{ format('{0}', github.event.inputs.dry_run) || env.DEFAULT_DRY_RUN }}" >> $GITHUB_ENV
echo "registry=${{ github.event.inputs.registry || env.DEFAULT_REGISTRY }}" >> $GITHUB_ENV
- uses: actions/checkout@v3

- name: Get Meltano version
Expand All @@ -51,25 +62,11 @@ jobs:
poetry version --short
echo "::set-output name=release-version::$(poetry version --short)"
# These exist to show if 'dry-run' flag is set as intended and correctly parsed from inputs
- name: Print dry-run message (if applicable)
if: ${{ env.DRY_RUN_STR == 'true' }}
run: |
echo "DRY_RUN=${{ github.event.inputs.dry-run }}"
echo "NOTE: This job is a dry run and will not publish any images."
- name: Print publish message (if applicable)
if: ${{ env.DRY_RUN_STR == 'false' }}
run: |
echo "DRY_RUN=${{ github.event.inputs.dry-run }}"
echo "NOTE: This job is planning to publish the docker images."
echo "⚠️ If this is not intended, please cancel this job."
- name: Assemble image tags
id: assemble-tags
run: |
# To save space, only publish the `latest` tag for each images to the GitHub registry
if [[ "${{ github.event.inputs.registry }}" != "ghcr.io" ]]; then
if [[ "${{ env.registry }}" != "ghcr.io" ]]; then
echo "v${{ steps.get-meltano-version.outputs.release-version }}-python${{ matrix.python-version }}" >> tags
[[ "${{ matrix.is-default-python }}" == "true" ]] && echo "SHA-${{ github.sha }}" >> tags
[[ "${{ matrix.is-default-python }}" == "true" ]] && echo "v${{ steps.get-meltano-version.outputs.release-version }}" >> tags
Expand All @@ -89,22 +86,22 @@ jobs:
- name: Set registry username and password
id: user-and-pass
run: |
if [[ "${{ github.event.inputs.registry }}" == "ghcr.io" ]]; then
if [[ "${{ env.registry }}" == "ghcr.io" ]]; then
echo "::set-output name=username::${{ github.actor }}"
echo "::set-output name=password::${{ secrets.GITHUB_TOKEN }}"
fi
if [[ "${{ github.event.inputs.registry }}" == "docker.io" ]]; then
if [[ "${{ env.registry }}" == "docker.io" ]]; then
echo "::set-output name=username::meltano"
echo "::set-output name=password::${{ secrets.DOCKERHUB_TOKEN }}"
fi
- name: Build, scan, then conditionally push the Docker image for a given Python version
uses: ./.github/actions/docker-build-scan-push
with:
push: ${{ env.DRY_RUN_STR == 'false' }}
push: ${{ env.dry_run == 'false' }}
token: ${{ secrets.GITHUB_TOKEN }}
tags: ${{ steps.assemble-tags.outputs.tags }}
registry: ${{ github.event.inputs.registry }}
registry: ${{ env.registry }}
username: ${{ steps.user-and-pass.outputs.username }}
password: ${{ steps.user-and-pass.outputs.password }}
python-version: ${{ matrix.python-version }}
Expand Down

0 comments on commit cdddf54

Please sign in to comment.