Update pre-commit
hooks (#266)
#107
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: CI - New updates to 'main' | |
on: | |
push: | |
branches: [main] | |
env: | |
DEPENDABOT_BRANCH: ci/dependabot-updates | |
GIT_USER_NAME: CasperWA | |
GIT_USER_EMAIL: "[email protected]" | |
DEFAULT_REPO_BRANCH: main | |
jobs: | |
update-dependabot-branch: | |
name: Update permanent dependabot branch | |
if: github.repository_owner == 'CasperWA' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.DEPENDABOT_BRANCH }} | |
fetch-depth: 0 | |
token: ${{ secrets.CI_RESET_TEST_BRANCHES }} | |
- name: Set up git config | |
run: | | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
- name: Update '${{ env.DEPENDABOT_BRANCH }}' | |
run: | | |
git fetch origin | |
LATEST_PR_BODY="$(gh api /repos/${{ github.repository}}/pulls -X GET -f state=closed -f per_page=1 -f sort=updated -f direction=desc --jq '.[].body')" | |
if [ "${LATEST_PR_BODY}" == "$(cat .github/utils/single_dependency_pr_body.txt)" ]; then | |
# The dependency branch has just been merged into `${{ env.DEFAULT_REPO_BRANCH }}` | |
# The dependency branch should be reset to `${{ env.DEFAULT_REPO_BRANCH }}` | |
echo "The dependencies have just been updated! Reset to ${{ env.DEFAULT_REPO_BRANCH }}." | |
git reset --hard origin/${{ env.DEFAULT_REPO_BRANCH }} | |
else | |
# Normal procedure: Merge `${{ env.DEFAULT_REPO_BRANCH }}` into `${{ env.DEPENDABOT_BRANCH }}` | |
echo "Merge new updates to ${{ env.DEFAULT_REPO_BRANCH }} into ${DEPENDABOT_BRANCH}" | |
git merge -m "Keep '${{ env.DEPENDABOT_BRANCH }}' up-to-date with '${{ env.DEFAULT_REPO_BRANCH }}'" origin/${{ env.DEFAULT_REPO_BRANCH }} | |
fi | |
git push -f | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
update-master-tag: | |
name: Update the `master` tag | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up git config | |
run: | | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
- name: Update tag | |
run: | | |
git tag -l master --format "%(contents:subject)%0a%0a%(contents:body)" > MASTER_TAG_MSG.txt | |
git tag -af -F "MASTER_TAG_MSG.txt" master | |
rm -f MASTER_TAG_MSG.txt | |
- name: Assert no commit changes occured | |
run: | | |
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/${{ env.DEFAULT_REPO_BRANCH }})" ]; then | |
echo "The current commit is NOT the same as the latest commit of '${{ env.DEFAULT_REPO_BRANCH }}'." | |
echo " HEAD: $(git rev-parse HEAD)" | |
echo " origin/${{ env.DEFAULT_REPO_BRANCH }}: $(git rev-parse origin/${{ env.DEFAULT_REPO_BRANCH }})" | |
exit 1 | |
fi | |
- name: Push updated tag | |
uses: ./ | |
with: | |
token: ${{ secrets.CI_RESET_TEST_BRANCHES }} | |
branch: ${{ env.DEFAULT_REPO_BRANCH }} | |
force: true | |
tags: true |