Initialization procedure #1
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: Initialization procedure | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| install-release-subrepo: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository (full history) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install git-subrepo | |
| shell: bash | |
| run: | | |
| git clone https://github.com/ingydotnet/git-subrepo ~/.git-subrepo | |
| echo "$HOME/.git-subrepo/lib" >> "$GITHUB_PATH" | |
| - name: Check git-subrepo installation | |
| shell: bash | |
| run: git subrepo --version | |
| - name: Configure git identity for commits | |
| shell: bash | |
| run: | | |
| git config user.name "GitHub Action" | |
| git config user.email "action@github.com" | |
| - name: Check if release branch exists | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| ORIGIN_URL="$(git remote get-url origin 2>/dev/null || true)" | |
| if [[ -z "$ORIGIN_URL" ]]; then | |
| echo "Error: could not find 'origin' remote URL." >&2 | |
| exit 1 | |
| fi | |
| if ! git ls-remote --heads "$ORIGIN_URL" release | grep -q 'refs/heads/release'; then | |
| echo "Warning: 'release' branch does not exist on $ORIGIN_URL" >&2 | |
| echo "The subrepo clone step will fail. You likely did not select 'Include all branches' when creating the repository from the dependency template." >&2 | |
| exit 1 | |
| else | |
| echo "'release' branch exists on $ORIGIN_URL" | |
| fi | |
| - name: Create release subrepo clone | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| ORIGIN_URL="$(git remote get-url origin 2>/dev/null || true)" | |
| if [[ -z "$ORIGIN_URL" ]]; then | |
| echo "Error: could not find 'origin' remote URL." >&2 | |
| exit 1 | |
| fi | |
| if [[ -d "release" && -n "$(ls -A release 2>/dev/null)" ]]; then | |
| echo "Error: './release' already exists and is not empty. Remove it or choose another directory before running." >&2 | |
| exit 1 | |
| fi | |
| git subrepo clone --branch=release "$ORIGIN_URL" release | |
| echo "Pushing 'main'..." | |
| git push -u origin main | |
| - name: Populate README with installation details | |
| shell: bash | |
| run: | | |
| bash -c "$(curl -fsSL https://raw.githubusercontent.com/pmalacho-mit/subrepo-dependency-management/refs/heads/main/scripts/populate-readme-after-init.sh)" | |
| - name: Commit and push updated README | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ -n "$(git status --porcelain README.md)" ]]; then | |
| git add README.md | |
| git commit -m "chore(suede-init): update README after initialization" | |
| git push | |
| else | |
| echo "No changes to README.md to commit." | |
| fi | |
| - name: Delete initialize action (aka this file) | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| FILE=".github/workflows/initialize.yml" | |
| if [[ -f "$FILE" ]]; then | |
| echo "Removing $FILE..." | |
| git rm -f "$FILE" | |
| # Commit and push if there are staged changes | |
| if [[ -n "$(git status --porcelain)" ]]; then | |
| git commit -m "chore(suede-init): remove initialization workflow" | |
| git push | |
| else | |
| echo "No changes to commit after removing $FILE." | |
| fi | |
| else | |
| echo "File $FILE not found; nothing to delete." | |
| fi |