Updated export workflow to allow zero change pushes #2
This file contains hidden or 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: Submodule Export Branch | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| export: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git | |
| run: | | |
| git config user.name "submodule-action" | |
| git config user.email "git@liamsherwin.com" | |
| - name: Set global variables | |
| run: | | |
| REPO_NAME="${GITHUB_REPOSITORY##*/}" | |
| echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV | |
| EXPORT_BRANCH="${REPO_NAME}-submodule" | |
| echo "EXPORT_BRANCH=$EXPORT_BRANCH" >> $GITHUB_ENV | |
| BLACKLIST=".github/submodule-blacklist.txt" | |
| echo "BLACKLIST=$BLACKLIST" >> $GITHUB_ENV | |
| - name: Create export branch | |
| run: | | |
| git checkout -B "$EXPORT_BRANCH" origin/main | |
| - name: Apply blacklist | |
| run: | | |
| if [ ! -f "$BLACKLIST" ]; then | |
| echo "Missing blacklist file: $BLACKLIST" | |
| exit 1 | |
| fi | |
| echo "Removing blacklisted paths:" | |
| while IFS= read -r line || [ -n "$line" ]; do | |
| [[ "$line" =~ ^#.*$ || -z "$line" ]] && continue | |
| echo "Removing: $line" | |
| rm -rf $line | |
| done < "$BLACKLIST" | |
| - name: Commit Changes (if any) | |
| run: | | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Submodule Export" | |
| fi | |
| - name: Push export branch | |
| run: | | |
| git push --set-upstream origin "$EXPORT_BRANCH" --force |