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
# Calls shared workflow to correct submodule URLs | |
# Github pushes are triggered by mirror operations from Gitlab. | |
# This workflow will only affect Github, not Gitlab. | |
name: call-submodule-corrector | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
# call-submodule-corrector: | |
# uses: tropicsquare/workflow-templates/.github/workflows/shared-correct-submodule-urls.yml@master | |
modify-gitmodules: | |
runs-on: ubuntu-22.04 | |
container: | |
image: python:alpine | |
volumes: | |
- ${{ github.workspace }}/.gitmodules:/.gitmodules | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Correct .gitmodules paths | |
shell: python | |
# Replaces '../foo/bar/repo.git' type urls with '../repo.git' | |
run: | | |
with open(".gitmodules", "r") as f: | |
lines = f.readlines() | |
for i, line in enumerate(lines): | |
if line.strip().startswith("url ="): | |
url = line.strip()[6:] | |
repo_name = url.rstrip('/').split('/')[-1] | |
lines[i] = f"\turl = ../{repo_name}\n" | |
with open(".gitmodules", "w") as f: | |
f.writelines(lines) | |
- name: Save Cache | |
id: cache-save | |
uses: actions/cache@v2 | |
with: | |
path: ${{ github.workspace }}/.gitmodules | |
key: ${{ runner.os }}-gitmodules | |
commit-changes: | |
runs-on: ubuntu-22.04 | |
needs: [modify-gitmodules] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Restore Cache | |
id: cache-hit | |
if: steps.cache-save.outputs.cache-hit != 'true' | |
uses: actions/cache@v3 | |
with: | |
path: ${{ github.workspace }}/artifacts/.gitmodules | |
key: ${{ runner.os }}-gitmodules | |
- name: Check if nothing to commit | |
id: check-diff | |
run: | | |
mv artifacts/.gitmodules .gitmodules | |
git diff --quiet .gitmodules || echo "::set-output name=changes::true" | |
- name: Commit and push | |
if: steps.check-diff.outputs.changes == 'true' | |
run: | | |
mv artifacts/.gitmodules .gitmodules | |
git config --global user.name "[bot]submodule-corrector" | |
git config --global user.email "[bot][email protected]" | |
git add .gitmodules | |
git commit -m "Autocorrect submodule URLs" | |
git push origin master | |