Sync+build+push HRConvert2-Docker #916
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: Sync+build+push HRConvert2-Docker | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
# push: | |
# branches: [ main ] | |
# pull_request: | |
# branches: [ main ] | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: '0 0 * * *' | |
workflow_dispatch: # Allows manually triggering from the Actions page | |
jobs: | |
get_commits: | |
runs-on: ubuntu-latest | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
outputs: | |
LOCAL_ORIGINAL_REPO: ${{ steps.commits.outputs.SETLOCAL_ORIGINAL_REPO }} | |
REMOTE_ORIGINAL_REPO: ${{ steps.commits.outputs.SETREMOTE_ORIGINAL_REPO }} | |
LOCAL_DOCKERFILE: ${{ steps.commits.outputs.SETLOCAL_DOCKERFILE }} | |
REMOTE_DOCKERFILE: ${{ steps.commits.outputs.SETREMOTE_DOCKERFILE }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'HRConvert2-Docker' # branch | |
- name: set local and remote latest commit as environment variables | |
id: commits | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs | |
run: | | |
echo "SETREMOTE_ORIGINAL_REPO=$(git ls-remote https://github.com/zelon88/HRConvert2 HEAD | awk '{ print $1 }')" >> $GITHUB_OUTPUT | |
echo "SETLOCAL_ORIGINAL_REPO=$(cat last_sync_with_original_repo_commit_id_original_repo)" >> $GITHUB_OUTPUT | |
echo "SETREMOTE_DOCKERFILE=$(git ls-remote https://github.com/dwaaan/HRConvert2-Docker HEAD | awk '{ print $1 }')" >> $GITHUB_OUTPUT | |
echo "SETLOCAL_DOCKERFILE=$(cat last_sync_with_original_repo_commit_id_dockerfile)" >> $GITHUB_OUTPUT | |
repo_sync: | |
needs: [get_commits] | |
runs-on: ubuntu-latest | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
if: needs.get_commits.outputs.LOCAL_ORIGINAL_REPO != needs.get_commits.outputs.REMOTE_ORIGINAL_REPO || needs.get_commits.outputs.LOCAL_DOCKERFILE != needs.get_commits.outputs.REMOTE_DOCKERFILE | |
steps: | |
- name: repo-sync | |
uses: wei/git-sync@v3 | |
with: | |
source_repo: "https://github.com/dwaaan/HRConvert2-Docker" | |
source_branch: "master" | |
destination_repo: "[email protected]:schklom/Mirror-workflows.git" | |
destination_branch: "HRConvert2-Docker" | |
ssh_private_key: ${{ secrets.GITSYNCACTION }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'HRConvert2-Docker' # branch | |
- name: get most recent commit id on original repo, for next comparison on sync | |
run: git ls-remote https://github.com/zelon88/HRConvert2 HEAD | awk '{ print $1 }' > last_sync_with_original_repo_commit_id_original_repo | |
- name: get most recent commit id on Dockerfile repo, for next comparison on sync | |
run: git ls-remote https://github.com/dwaaan/HRConvert2-Docker HEAD | awk '{ print $1 }' > last_sync_with_original_repo_commit_id_dockerfile | |
- name: Commit and push the change | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: Add last_sync_with_original_repo_commit_id_original_repo and last_sync_with_original_repo_commit_id_dockerfile | |
build_push: | |
needs: [repo_sync] | |
#needs: [get_commits] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'HRConvert2-Docker' # branch | |
# https://github.com/docker/setup-qemu-action#usage | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
#with: | |
#image: tonistiigi/binfmt:latest | |
#platforms: all | |
#platforms: arm/v7 | |
# https://github.com/marketplace/actions/docker-setup-buildx | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/[email protected] | |
#with: | |
#install: true | |
#- name: Available platforms | |
# run: echo ${{ steps.buildx.outputs.platforms }} | |
# https://github.com/docker/login-action#docker-hub | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# https://github.com/docker/build-push-action#multi-platform-image | |
- name: Build and push HRConvert2-Docker | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile | |
#platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x | |
platforms: linux/amd64,linux/arm64 | |
pull: true | |
push: true | |
tags: | | |
schklom/hrconvert2:latest |