Sync+build+push Wikiless #879
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 Wikiless | |
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: | |
parameters: | |
runs-on: ubuntu-latest | |
outputs: | |
LOCAL_BRANCH: Wikiless | |
REMOTE_REPOSITORY_1: https://github.com/Metastem/wikiless | |
REMOTE_REPOSITORY_1_BRANCH: ${{ steps.branch_name.outputs.SET_REMOTE_REPOSITORY_1_BRANCH }} | |
steps: | |
- name: find HEAD branch name dynamically | |
id: branch_name | |
run: echo "SET_REMOTE_REPOSITORY_1_BRANCH=$(git ls-remote --symref https://github.com/Metastem/wikiless HEAD | grep '^ref:' | cut -d' ' -f2 | sed 's|refs/heads/||' | awk '{print $1}')" >> $GITHUB_OUTPUT | |
get_commits: | |
needs: [parameters] | |
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: "${{ needs.parameters.outputs.LOCAL_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=$(git ls-remote ${{ needs.parameters.outputs.REMOTE_REPOSITORY_1 }} ${{ needs.parameters.outputs.REMOTE_REPOSITORY_1_BRANCH }} | awk '{ print $1 }')" >> $GITHUB_OUTPUT | |
echo "SETLOCAL=$(cat last_sync_with_original_repo_commit_id)" >> $GITHUB_OUTPUT | |
repo_sync: | |
needs: [get_commits, parameters] | |
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: "${{ needs.parameters.outputs.REMOTE_REPOSITORY_1 }}" | |
source_branch: "${{ needs.parameters.outputs.REMOTE_REPOSITORY_1_BRANCH }}" | |
destination_repo: "git@github.com:schklom/Mirror-workflows.git" | |
destination_branch: "${{ needs.parameters.outputs.LOCAL_BRANCH }}" | |
ssh_private_key: ${{ secrets.GITSYNCACTION }} | |
# uses: repo-sync/github-sync@v2 | |
# with: | |
# source_repo: "https://github.com/hkalexling/Wikiless.git" | |
# source_branch: "master" | |
# destination_branch: "Wikiless" | |
# github_token: ${{ secrets.REPO_SYNC_GITHUB_SYNC_PERSONAL_ACCESS_TOKEN }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: "${{ needs.parameters.outputs.LOCAL_BRANCH }}" | |
- name: get most recent commit id on original repo, for next comparison on sync | |
run: git ls-remote "${{ needs.parameters.outputs.REMOTE_REPOSITORY_1 }}" "${{ needs.parameters.outputs.REMOTE_REPOSITORY_1_BRANCH }}" | 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 | |
build_push: | |
needs: [repo_sync, parameters] | |
#needs: [get_commits] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
#repository: 'schklom/Wikiless' | |
ref: ${{ needs.parameters.outputs.LOCAL_BRANCH }} | |
# https://github.com/docker/setup-qemu-action#usage | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3.3.0 | |
#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/setup-buildx-action@v3.8.0 | |
#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 ${{ needs.parameters.outputs.LOCAL_BRANCH }} | |
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/amd64,linux/arm64 | |
pull: true | |
push: true | |
tags: | | |
schklom/wikiless:latest |