small refactor

This commit is contained in:
Alexander
2023-08-28 16:23:41 +02:00
parent 4bc01a9ab0
commit 05dfb923b3
7 changed files with 220 additions and 22 deletions
@@ -0,0 +1,27 @@
# Alexander Tebiev - https://github.com/beeyev
name: Prepare Docker env variables
description: 'Prepare env variables'
outputs:
DATE_YEAR_WEEKNUM:
description: "DATE_YEAR_WEEKNUM"
value: ${{ steps.prepare-env-variables.outputs.DATE_YEAR_WEEKNUM }}
BUILD_DATE:
description: "BUILD_DATE"
value: ${{ steps.prepare-env-variables.outputs.BUILD_DATE }}
BUILD_FINGERPRINT:
description: "BUILD_FINGERPRINT"
value: ${{ steps.prepare-env-variables.outputs.BUILD_FINGERPRINT }}
CURRENT_BRANCH_NAME:
description: "CURRENT_BRANCH_NAME"
value: ${{ steps.prepare-env-variables.outputs.CURRENT_BRANCH_NAME }}
runs:
using: "composite"
steps:
- id: prepare-env-variables
shell: bash
run: |
echo "DATE_YEAR_WEEKNUM=$(TZ=':UTC' date +'%Y-%U')" >> ${GITHUB_OUTPUT}
echo "BUILD_DATE=$(date -u +'%Y-%m-%d %H:%M:%S (%Z)')" >> ${GITHUB_OUTPUT}
echo "NOW_RFC_3339=$(date -u --rfc-3339=seconds | sed 's/ /T/')" >> ${GITHUB_OUTPUT}
echo "BUILD_FINGERPRINT=$(git rev-parse --short HEAD)" >> ${GITHUB_OUTPUT}
echo "CURRENT_BRANCH_NAME=$(git branch --show-current)" >> ${GITHUB_OUTPUT}
@@ -0,0 +1,60 @@
# Alexander Tebiev - https://github.com/beeyev
on:
workflow_call:
inputs:
DOCKER_REGISTRY_IMAGE:
required: true
type: string
DOCKERFILE_PATH:
required: true
type: string
BASE_IMAGE_VERSION:
required: true
type: string
jobs:
build-docker-image:
name: Build Docker Image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout branch - ${{ github.head_ref || github.ref_name }}
uses: actions/checkout@v3
- name: Prepare Build Env Variables
uses: ./.github/actions/prepare-env-variables/
id: prepare-build-env-variables
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}
- name: Build image and push to registry - ${{ inputs.DOCKER_REGISTRY_IMAGE }}
uses: docker/build-push-action@v4
with:
platforms: linux/amd64
context: .
file: ${{ inputs.DOCKERFILE_PATH }}
cache-from: type=registry,ref=${{ inputs.DOCKER_REGISTRY_IMAGE }}
cache-to: type=inline
build-args: |
BASE_IMAGE_VERSION=${{ inputs.BASE_IMAGE_VERSION }}
BUILD_DATE=${{ steps.prepare-build-env-variables.outputs.BUILD_DATE }}
BUILD_FINGERPRINT=${{ steps.prepare-build-env-variables.outputs.BUILD_FINGERPRINT }}
BRANCH_NAME=${{ steps.prepare-build-env-variables.outputs.CURRENT_BRANCH_NAME }}
tags: ${{ inputs.DOCKER_REGISTRY_IMAGE }}
push: true
@@ -0,0 +1,58 @@
# Alexander Tebiev - https://github.com/beeyev
name: Delete old workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 30
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
required: true
default: 6
delete_workflow_pattern:
description: 'The name or filename of the workflow. if not set then it will target all workflows.'
required: false
delete_workflow_by_state_pattern:
description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: "All"
type: choice
options:
- "All"
- active
- deleted
- disabled_inactivity
- disabled_manually
delete_run_by_conclusion_pattern:
description: 'Remove workflow by conclusion: action_required, cancelled, failure, skipped, success'
required: true
default: "All"
type: choice
options:
- "All"
- action_required
- cancelled
- failure
- skipped
- success
dry_run:
description: 'Only log actions, do not perform any delete operations.'
required: false
jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
dry_run: ${{ github.event.inputs.dry_run }}
@@ -0,0 +1,43 @@
# Alexander Tebiev - https://github.com/beeyev
name: Build Test Docker Images
on:
pull_request:
types: [labeled]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
initialization:
name: Initialization
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: contains(github.event.label.name, 'make-test-build')
# if: |
# (github.event.action == 'labeled' && github.event.label.name == 'make-test-build') ||
# (github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'make-test-build'))
steps:
- name: Remove `test-build` label
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: make-test-build
- name: Sticky Pull Request Comment
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
> [Building test docker images...](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
docker-image-deploy:
uses: ./.github/workflows/callable-build-docker-image.yml
name: Build Test Docker Images / ${{ matrix.baseDist }}-test
with:
BASE_IMAGE_VERSION: 5.2-fpm-alpine
DOCKER_REGISTRY_IMAGE: ghcr.io/beeyev/phpmyadmin-docker-lightweight:test
DOCKERFILE_PATH: ./docker/Dockerfile
secrets: inherit