trigger-submodule-update #3
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
--- | |
# yamllint disable rule:truthy rule:line-length | |
name: Handle Submodule Trigger | |
on: | |
repository_dispatch: | |
types: | |
- trigger-submodule-update | |
jobs: | |
update-dependencies: | |
strategy: | |
matrix: | |
branch-name: | |
- stable | |
- develop | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: "${{ matrix.branch-name }}" | |
submodules: recursive | |
- name: Set branch name | |
id: set-branch-name | |
run: | | |
SUBMODULE_PATH="python_sdk" | |
SDK_VERSION="${{ github.event.client_payload.version }}" | |
BRANCH_NAME="${{ matrix.branch-name}}-${SUBMODULE_PATH}-${SDK_VERSION}" | |
echo "SUBMODULE_PATH=$SUBMODULE_PATH" >> $GITHUB_ENV | |
echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Use the version from the client payload to update the submodule | |
run: | | |
echo "Updating submodule to version: ${{ env.SDK_VERSION }}" | |
echo "Branch name: ${{ env.BRANCH_NAME }}" | |
# Navigate to the submodule and update it to the specified version | |
cd ${{ env.SUBMODULE_PATH }} | |
git fetch --tags | |
git checkout ${{ env.SDK_VERSION }} | |
cd - | |
- name: Prepare the branch for the update | |
id: prepare-branch | |
run: | | |
echo "Checking if branch ${{ env.BRANCH_NAME }} exists..." | |
BRANCH_EXISTS=$(git ls-remote --heads origin ${{ env.BRANCH_NAME }} | wc -l) | |
echo "BRANCH_EXISTS=$BRANCH_EXISTS" >> $GITHUB_ENV | |
- name: Commit and push changes with github-actions-x/commit | |
uses: github-actions-x/commit@v2.9 | |
with: | |
github-token: ${{ secrets.GH_UPDATE_PACKAGE_OTTO }} | |
push-branch: ${{ env.BRANCH_NAME }} | |
commit-message: "chore: update submodule ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }}" | |
files: ${{ env.SUBMODULE_PATH }}/ | |
name: opsmill-bot | |
email: github-bot@opsmill.com | |
rebase: ${{ env.BRANCH_EXISTS == 1 }} | |
- name: Create a pull request | |
run: | | |
echo ${{ secrets.GH_UPDATE_PACKAGE_OTTO }} | gh auth login --with-token | |
gh pr create \ | |
--title "Update ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }} against ${{ matrix.branch-name}}" \ | |
--body "This PR updates the submodule ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }}." \ | |
--base ${{ matrix.branch-name}} \ | |
--head ${{ env.BRANCH_NAME }} |