🤖: Bump cachix/install-nix-action in /.github/actions/runner (#331) #151
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
# Sometimes template and main get out of wack. | |
# This tries to rectify that | |
name: sync template | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ template ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: sync | |
run: | | |
echo "::group::Setup Git" | |
echo ">> Actor:${{ github.actor }}" | |
git config --global user.name '${{ github.actor }}' | |
git config --global user.email '${{ github.actor }}@users.noreply.github.com' | |
echo "::endgroup::" | |
# Aggressively resolve merge. | |
echo "::group::Merge" | |
cp ./.github/workflows/sync.yml ~ | |
git fetch | |
git merge -s recursive -X ours origin/main || echo "merge failed (no branch?)" | |
git status | grep -P 'deleted by us|added by them' | awk '{print $4}' | xargs git rm || echo fine | |
# Update remote if changed | |
previous_user=$(cat .github/assets/remote.txt | cut -d/ -f4) | |
previous=$(cat .github/assets/remote.txt | cut -d/ -f4-5) | |
echo "$(git remote get-url origin)" > .github/assets/remote.txt | |
updated=$(cat .github/assets/remote.txt | cut -d/ -f4-5) | |
updated_user=$(cat .github/assets/remote.txt | cut -d/ -f4) | |
# Update references to remote (if applicable) | |
find .github/ -type f | xargs sed -i "s@$previous@$updated@g" | |
find .github/ -type f | xargs sed -i "s@$previous_user@$updated_user@g" | |
# Commit sync or open pr. Overwrite any changes made to sync.yml! | |
cp ~/sync.yml ./.github/workflows/sync.yml | |
echo "::endgroup::" | |
echo "::group::Sync" | |
# Check if this is a new template | |
git rev-parse --verify origin/main || { | |
sed -i '/#examples\s*-/,/\/examples\s*-/{/^#/!{/^\$/!d;};}' ./.github/README.md | |
} | |
git add --all | |
git commit -am "♻️" || echo "resolved" | |
# if this failed you probably didn't make workflow changes on template | |
git push | |
# if main doesn't exist we should make it (new template) | |
git rev-parse --verify origin/main || { | |
git checkout -b main && git push origin main; | |
ERROR=$(gh issue create -a '${{ github.actor }}' -t "finish setting up template" -F ./.github/template_todo.md 2>&1) | |
# Check if the command succeeded or failed | |
if [[ $? -ne 0 ]]; then # if the command failed | |
# If a "403" is in the output, then perform the following commands | |
if [[ -n "$ERROR" ]] && echo "$ERROR" | grep -q "403"; then | |
# cat .github/workflow-setup.md >> $GITHUB_STEP_SUMMARY | |
echo "# Auth probz" >> $GITHUB_STEP_SUMMARY | |
fi | |
echo "\n---" >> $GITHUB_STEP_SUMMARY | |
echo "the raw error: $ERROR" >> $GITHUB_STEP_SUMMARY | |
exit 1 # make the script fail | |
fi | |
} | |
echo "::endgroup::" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: sync-back | |
run: | | |
cp -r .github ~/github | |
git checkout main | |
rm -rf .github | |
cp -r ~/github .github | |
git add --all | |
git commit -am "♻️" && git push || echo "resolved" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |