Skip to content

Commit

Permalink
Use create-pull-request for update of submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Aug 14, 2024
1 parent f0e19b0 commit b717615
Showing 1 changed file with 25 additions and 56 deletions.
81 changes: 25 additions & 56 deletions .github/workflows/update-submodules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,37 @@ on:
jobs:
update-submodules:
runs-on: ubuntu-latest
strategy:
matrix:
submodule:
- tomlplusplus
- vcpkg

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update submodules to latest release
id: git-change-job
run: |
cd ThirdParty
git fetch --all
submodules=("fast_float" "spdlog" "tomlplusplus" )
for submodule in "${submodules[@]}"; do
BRANCH_NAME=ci-update-$submodule
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists."
git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME"
else
echo "Branch $BRANCH_NAME does not exist. Creating branch."
git checkout -b "$BRANCH_NAME"
fi
cd $submodule
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ -n "$latest_tag" ]; then
git checkout $latest_tag
else
echo "Empty tag detected in $submodule. Nothing to do."
fi
cd ..
if git diff --quiet; then
echo "No changes detected in $submodule"
else
git add $submodule
git commit -m "Update $submodule to $latest_tag" || echo "No changes to commit"
git push origin "$BRANCH_NAME"
fi
git checkout dev
git reset --hard origin/dev --recurse-submodule
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Pull Requests for each submodule
run: |
submodules=("fast_float" "spdlog" "tomlplusplus" )
for submodule in "${submodules[@]}"; do
gh pr create --title "Update $submodule to latest release" --body "This PR updates the $submodule submodule to its latest release." --head ci-update-$submodule --base dev
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cd ThirdParty/${{ matrix.submodule }}
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ -n "$latest_tag" ]; then
git checkout $latest_tag
echo "LATEST_TAG=$latest_tag" >> "$GITHUB_OUTPUT"
else
echo "Empty tag detected in ${{ matrix.submodule }}. Nothing to do."
fi
- name: Create PR
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update ${{ matrix.submodule }} to ${{ steps.git-change-job.outputs.LATEST_TAG }}"
title: "Update ${{ matrix.submodule }} to ${{ steps.git-change-job.outputs.LATEST_TAG }}"
branch: ci-update-${{ matrix.submodule }}
branch-suffix: random

0 comments on commit b717615

Please sign in to comment.