33
44name : Sync with template repository
55on :
6+ workflow_dispatch :
7+
68 schedule :
79 - cron : 11 11 * * *
810
911permissions :
1012 contents : read
11- env :
12- # This is the username and email for the user who creates a branch and commits
13- # the changes. In an organisation that should be a dedicated devops account.
14- USER_NAME : jenstroeger
15- USER_EMAIL : jenstroeger@users.noreply.github.com
1613
1714jobs :
1815 sync :
@@ -44,14 +41,18 @@ jobs:
4441 - name : Sync with template
4542 env :
4643 GH_TOKEN : ${{ secrets.REPO_ACCESS_TOKEN }}
44+ # This is the username and email for the user who creates a branch and commits
45+ # the changes. In an organisation that should be a dedicated devops account.
46+ USER_NAME : jenstroeger
47+ USER_EMAIL : jenstroeger@users.noreply.github.com
48+ working-directory : ./repo
4749 run : |
48- LATEST_VERSION=$(cd template && git describe --tags --abbrev=0)
49- CURRENT_VERSION=$(test -f repo/.github/workflows/.template_version \
50- && cat repo/.github/workflows/.template_version || echo "v0.0.0")
51- echo "Latest version is $LATEST_VERSION and current version is $CURRENT_VERSION."
50+ LATEST_VERSION=$(cd ../template && git describe --tags --abbrev=0)
51+ CURRENT_VERSION=$(test -f .github/workflows/.template_version && cat .github/workflows/.template_version || echo "v0.0.0")
52+ echo "Latest version is ${LATEST_VERSION} and current version is ${CURRENT_VERSION}."
5253
5354 # Check if the template repo was changed/updated.
54- if [ "$CURRENT_VERSION" == "$LATEST_VERSION" ]; then
55+ if [ "${ CURRENT_VERSION} " == "${ LATEST_VERSION} " ]; then
5556 echo "Unable to find a new version, exiting..."
5657 else
5758
@@ -61,17 +62,16 @@ jobs:
6162 echo "Branch $BRANCH_NAME already exists, exiting..."
6263 else
6364
64- # Generate a patch file of all template changes.
65- pushd template || exit
66- git diff "$CURRENT_VERSION..$LATEST_VERSION" "$(find . docs/ .github/ .github/workflows/ .github/codeql/ -maxdepth 1 -type f ! -name """*.md""" ! -name """.template_version""")" > diff.patch
65+ # Generate a patch file of all template changes in the cloned template repository.
66+ pushd ../template || exit
67+ # shellcheck disable=SC2046
68+ git diff "${CURRENT_VERSION}".."${LATEST_VERSION}" -- $(find . docs/ .github/ .github/workflows/ -maxdepth 1 -type f ! -name "*.md" ! -name ".template_version") > diff.patch
6769 popd || exit
6870
6971 # Apply the generated patch to the current repo.
70- pushd repo || exit
7172 patch --strip 1 --batch --merge --input ../template/diff.patch || true
7273 find . -name "*.orig" -type f -delete
7374 find . -name "*.rej" -type f -delete
74- popd || exit
7575
7676 # Create a branch, commit, and push the changeset.
7777 git checkout -b "$BRANCH_NAME"
8484 git push --set-upstream origin "$BRANCH_NAME"
8585
8686 # Create the pull request.
87- gh pr create --base staging --title "chore: sync with package template $LATEST_VERSION" \
88- --body "This PR was generated automatically." --head "$BRANCH_NAME"
87+ gh pr create --base staging --head "$BRANCH_NAME" --title "chore: sync with template $LATEST_VERSION" --body "This PR was generated automatically."
8988
9089 fi
9190 fi
0 commit comments