Bypass checkout action #106
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: Docs | |
"on": | |
push: | |
# Only targets main branch to avoid amplification effects of auto-fixing | |
# the exact same stuff in multiple non-rebased branches. | |
branches: | |
- main | |
jobs: | |
#docs: | |
# uses: kdeldycke/workflows/.github/workflows/docs.yaml@v3.3.4 | |
awesome-template-sync: | |
name: Sync awesome template | |
if: > | |
startsWith(github.event.repository.name, 'awesome-') | |
&& github.event.repository.name != 'awesome-template' | |
runs-on: ubuntu-22.04 | |
env: | |
PR_COMMIT_MSG: "[sync] Updates from awesome-template" | |
# We need custom PAT through the whole job so we get workflow permissions to update all the boilerplate .github | |
# files from awesome-template. | |
steps: | |
- name: Initial checkout | |
uses: actions/checkout@v4.1.1 | |
with: | |
token: ${{ secrets.WORKFLOW_UPDATE_GITHUB_PAT || secrets.GITHUB_TOKEN }} | |
- name: Sync from template repo | |
id: template_sync | |
uses: AndreasAugustin/actions-template-sync@v1.8.1 | |
with: | |
github_token: ${{ secrets.WORKFLOW_UPDATE_GITHUB_PAT || secrets.GITHUB_TOKEN }} | |
source_repo_path: kdeldycke/awesome-template | |
pr_title: "[sync] Updates from `awesome-template`" | |
pr_commit_msg: ${{ env.PR_COMMIT_MSG }} | |
pr_branch_name_prefix: "sync-awesome-template" | |
pr_labels: "📚 documentation" | |
- name: Print PR branch ID | |
run: | | |
echo "PR branch ID: ${{ steps.template_sync.outputs.pr_branch }}" | |
#- name: Checkout new template sync branch | |
# uses: actions/checkout@v4.1.1 | |
# with: | |
# token: ${{ secrets.WORKFLOW_UPDATE_GITHUB_PAT || secrets.GITHUB_TOKEN }} | |
# ref: ${{ steps.template_sync.outputs.pr_branch }} | |
- run: | | |
git checkout ${{ steps.template_sync.outputs.pr_branch }} | |
# XXX We cannot rely on peter-evans/create-pull-request to manage the push of the new commit to the PR, as it | |
# ends up with a: "Unexpected error: fatal: could not open '.git/COMMIT_EDITMSG': Permission denied". | |
# See: https://github.com/AndreasAugustin/actions-template-sync/issues/484 | |
# So we manage the next steps with bare git calls. | |
- name: List commits | |
run: | | |
git log | |
- name: Update repo URLs | |
# Replace "/kdeldycke/awesome-template/" in URLs by "/kdeldycke/awesome-<repo_id>/". | |
run: > | |
find ./.github/ -type f -iregex ".*\.\(md\|yaml\)$" -print -exec sed -i | |
"s/\/kdeldycke\/awesome-template\//\/kdeldycke\/${{ github.event.repository.name }}\//g" "{}" \; | |
- name: Show diff | |
run: | | |
git diff | |
- name: Setup Git user | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Deactivate LFS | |
# XXX Was introduced in https://github.com/AndreasAugustin/actions-template-sync/commit/5335a55 | |
run: | | |
git config lfs.https://github.com/kdeldycke/${{ github.event.repository.name }}.git/info/lfs.locksverify false | |
- name: Create commit | |
run: | | |
git commit --all --message "Update template URLs with local ones" | |
- name: Combine the last 2 commits into one | |
# See: https://stackoverflow.com/a/26172014 | |
run: | | |
git reset --soft $(git merge-base main HEAD) | |
- name: Push new commit history to PR | |
run: | | |
git commit --message "${{ env.PR_COMMIT_MSG }}" | |
git push --force |