Update Submodule #2953
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
name: "Update Submodule" | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
inputs: | |
repo: | |
description: "Submodule to update" | |
required: true | |
branch: | |
description: "Branch of the submodule to update" | |
required: true | |
commit: | |
description: "Commit of the submodule to check out" | |
required: false | |
jobs: | |
sync: | |
name: "Update submodules" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Generate a token | |
id: generate_token | |
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 | |
with: | |
app_id: ${{ secrets.TEMPORAL_CICD_APP_ID }} | |
private_key: ${{ secrets.TEMPORAL_CICD_PRIVATE_KEY }} | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
submodules: true | |
persist-credentials: true | |
token: ${{ steps.generate_token.outputs.token }} | |
fetch-depth: 0 | |
- name: Calc target branches | |
id: target_branches | |
env: | |
LOCAL_BRANCH: ${{ github.event.inputs.branch }} | |
SUBMODULE_BRANCH: ${{ github.event.inputs.branch }} | |
run: | | |
if [[ $LOCAL_BRANCH == master ]]; then LOCAL_BRANCH=main; fi | |
echo "local_branch=${LOCAL_BRANCH}" >> $GITHUB_OUTPUT | |
echo "submodule_branch=${SUBMODULE_BRANCH}" >> $GITHUB_OUTPUT | |
- name: Create and switch branch | |
env: | |
BRANCH: ${{ steps.target_branches.outputs.local_branch }} | |
run: | | |
git switch "$BRANCH" || git switch -c "$BRANCH" | |
- name: Update Submodule branch | |
env: | |
SUBMODULE: ${{ github.event.inputs.repo }} | |
BRANCH: ${{ steps.target_branches.outputs.submodule_branch }} | |
run: | | |
if ! git config --file=.gitmodules --get submodule."$SUBMODULE".url >/dev/null; then | |
echo "unknown submodule $SUBMODULE" | |
exit 1 | |
fi | |
git config --file=.gitmodules submodule."$SUBMODULE".branch "$BRANCH" | |
git submodule update --init --recursive --remote "$SUBMODULE" | |
- name: Check out requested commit | |
if: github.event.inputs.commit | |
env: | |
SUBMODULE: ${{ github.event.inputs.repo }} | |
COMMIT: ${{ github.event.inputs.commit }} | |
run: | | |
# We know the submodule exists by this point | |
cd $(git config --file=.gitmodules --get submodule."$SUBMODULE".path) && git checkout "$COMMIT" | |
- name: Commit update | |
env: | |
CURRENT_REPO: ${{ github.repository }} | |
TOKEN: ${{ steps.generate_token.outputs.token }} | |
SUBMODULE: ${{ github.event.inputs.repo }} | |
BRANCH: ${{ steps.target_branches.outputs.local_branch }} | |
run: | | |
git config --local user.name 'Temporal Data (cicd)' | |
git config --local user.email 'commander-data@temporal.io' | |
git remote set-url origin "https://x-access-token:$TOKEN@github.com/$CURRENT_REPO" | |
git add . | |
git commit -m "Update $SUBMODULE submodule for branch $BRANCH" | |
git push origin "$BRANCH" |