Skip to content

Commit

Permalink
Add GHA workflow manifest-sync.yml
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Oct 2, 2024
1 parent 76748f6 commit f9fda5b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/manifest_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: manifest synchronisation

on:
workflow_call:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }}-${{ inputs.additional_key }}
cancel-in-progress: true

env:
WORKTREE_PATH: /tmp/workspace

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Checkout manifest-schema branch
run: ./tools/checkout-manifest-schema-branch.sh $WORKTREE_PATH

- name: Copy over schema
run: cp ./manifests/* $WORKTREE_PATH

- name: Stage changes
working-directory: ${{ env.WORKTREE_PATH }}
run: git add .

- name: Show diff
working-directory: ${{ env.WORKTREE_PATH }}
run: git diff

- name: Detect changes
id: changes
working-directory: ${{ env.WORKTREE_PATH }}
run: |
# This output boolean tells us if the dependencies have actually changed
echo "count=$(git status --porcelain=v1 | wc -l)" >> $GITHUB_OUTPUT
- name: Commit and push
# Only push if changes exist
if: steps.changes.outputs.count > 0
working-directory: ${{ env.WORKTREE_PATH }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git commit -m "Update manifest schema"
git push origin HEAD
19 changes: 19 additions & 0 deletions tools/checkout-manifest-schema-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -exuo pipefail

cd "$(dirname "$0")"

schema_version="$(grep 'version = "0.*.0"' ./manifest-schema/Cargo.toml | cut -d '.' -f 2)"
branch="manifest-schema-${schema_version}"

git worktree add --force "${1?}"
cd "${1?}"

if git fetch origin "$branch"; then
git checkout "origin/${branch}" -B "${branch}"
elif ! git checkout "$branch"; then
# New branch with no history. Credit: https://stackoverflow.com/a/13969482
git checkout --orphan "${branch}"
git rm --cached -r . || true
fi

0 comments on commit f9fda5b

Please sign in to comment.