Sync+build+push Pi.Alert #1108
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 Pi.Alert | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
get_commits: | |
runs-on: ubuntu-latest | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
outputs: | |
LOCAL: ${{ steps.commits.outputs.SETLOCAL }} | |
REMOTE: ${{ steps.commits.outputs.SETREMOTE }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'Pi.Alert' # branch | |
- name: set local and remote latest commit as environment variables | |
id: commits | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
run: | | |
echo "::set-output name=SETREMOTE::$(git ls-remote https://github.com/BarnardCollier/pialert.git HEAD | awk '{ print $1 }')" | |
echo "::set-output name=SETLOCAL::$(cat last_sync_with_original_repo_commit_id)" | |
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 != needs.get_commits.outputs.REMOTE | |
steps: | |
- name: repo-sync | |
uses: wei/git-sync@v3 | |
with: | |
source_repo: "https://github.com/BarnardCollier/pialert.git" | |
source_branch: "main" | |
destination_repo: "[email protected]:schklom/Mirror-workflows.git" | |
destination_branch: "Pi.Alert" | |
ssh_private_key: ${{ secrets.GITSYNCACTION }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'Pi.Alert' # branch | |
- name: get most recent commit id on original repo, for next comparison on sync | |
run: git ls-remote https://github.com/BarnardCollier/pialert.git HEAD | awk '{ print $1 }' > last_sync_with_original_repo_commit_id | |
- name: Commit and push the change | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: Add last_sync_with_original_repo_commit_id | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
#- uses: actions/checkout@v4 | |
#with: | |
#ref: 'Pi.Alert' | |
#- name: app dockerfile | |
# run: sed -r 's/^FROM ([a-zA-Z]+)(.*)$/FROM arm32v7\/\1\2/' src/app/Dockerfile > src/app/Dockerfile | |
#- name: adapt web dockerfile | |
# run: sed -r 's/^FROM abiosoft\/caddy:no-stats$/FROM jessestuart\/caddy/' web/Dockerfile > web/Dockerfile | |
# https://github.com/marketplace/actions/git-auto-commit | |
#- name: pushing web Dockerfile changes to main branch | |
# uses: stefanzweifel/git-auto-commit-action@v5 | |
# with: | |
# Optional but recommended | |
# Defaults to "Apply automatic changes" | |
# commit_message: Updated web Dockerfile to work with Raspberry Pi 4 | |
build_push: | |
needs: [repo_sync] | |
#needs: [get_commits] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
#repository: 'schklom/Pi.Alert' | |
ref: 'Pi.Alert' # 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 Pi.Alert | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile | |
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6 | |
# platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 | |
platforms: linux/arm/v7 | |
pull: true | |
push: true | |
tags: | | |
schklom/pi.alert:latest |