Update component submodules on main branch #295
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 component submodules on main branch | |
permissions: | |
id-token: write | |
on: | |
workflow_dispatch: | |
inputs: | |
bump-app: | |
description: Bump the app submodule | |
type: boolean | |
default: false | |
bump-tenant-manager: | |
description: Bump the tenant manager submodule | |
type: boolean | |
default: false | |
env: | |
GEMINI_LOCATION: europe-west3 | |
GEMINI_MODEL: gemini-1.5-pro | |
jobs: | |
update_submodules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Sanity check | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "This workflow updates only the main branch." | |
exit 1 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
submodules: false | |
persist-credentials: false | |
- name: Generate a token | |
id: generate_token | |
uses: actions/create-github-app-token@v1 | |
with: | |
app-id: ${{ vars.TENZIR_AUTOBUMPER_APP_ID }} | |
private-key: ${{ secrets.TENZIR_AUTOBUMPER_APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner }} | |
- uses: crazy-max/ghaction-import-gpg@v6 | |
with: | |
gpg_private_key: ${{ secrets.TENZIR_BOT_GPG_SIGNING_KEY }} | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
- name: Prepare git push | |
env: | |
GITHUB_APP_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
git config --global user.name 'tenzir-bot' | |
git config --global user.email '[email protected]' | |
git remote set-url origin https://x-access-token:[email protected]/tenzir/platform.git | |
- name: Configure ssh-agent for app submodule | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.TENZIR_APP_DEPLOY_KEY }} | |
- name: Authenticate with google cloud | |
id: gcloud-login | |
uses: 'google-github-actions/auth@v2' | |
continue-on-error: true | |
with: | |
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDP }} | |
service_account: ${{ vars.GCP_SERVICE_ACCOUNT }} | |
token_format: access_token | |
- name: Update app submodule | |
if: ${{ inputs.bump-app }} | |
env: | |
LOCATION: ${{ env.GEMINI_LOCATION }} | |
MODEL: ${{ env.GEMINI_MODEL }} | |
REPO: app | |
PROJECT_ID: ${{ steps.gcloud-login.outputs.project_id }} | |
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud-login.outputs.access_token }} | |
run: | | |
git submodule update --init --no-recommend-shallow components/app | |
current_sha=$(git -C components/app rev-parse HEAD) | |
current_sha_short=$(git -C components/app rev-parse --short HEAD) | |
upstream_sha=$(git -C components/app rev-parse origin/main) | |
upstream_sha_short=$(git -C components/app rev-parse --short origin/main) | |
if [ ${current_sha} != ${upstream_sha} ]; then | |
git -C components/app checkout origin/main | |
echo -e "Bump app component from ${current_sha_short} to ${upstream_sha_short}\n\n" > commitmsg | |
./scripts/describe-component-bump components/app ${current_sha} ${upstream_sha} >> commitmsg ||: | |
git add components/app | |
git commit -F commitmsg | |
git push -u origin main:main | |
fi | |
- name: Configure ssh-agent for tenant-manager submodule | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.TENZIR_EVENT_HORIZON_DEPLOY_KEY }} | |
- name: Update tenant-manager submodule | |
if: ${{ inputs.bump-tenant-manager }} | |
env: | |
LOCATION: ${{ env.GEMINI_LOCATION }} | |
MODEL: ${{ env.GEMINI_MODEL }} | |
REPO: event-horizon | |
PROJECT_ID: ${{ steps.gcloud-login.outputs.project_id }} | |
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud-login.outputs.access_token }} | |
run: | | |
git submodule update --init --no-recommend-shallow components/tenant-manager | |
current_sha=$(git -C components/tenant-manager rev-parse HEAD) | |
current_sha_short=$(git -C components/tenant-manager rev-parse --short HEAD) | |
upstream_sha=$(git -C components/tenant-manager rev-parse origin/main) | |
upstream_sha_short=$(git -C components/tenant-manager rev-parse --short origin/main) | |
if [ ${current_sha} != ${upstream_sha} ]; then | |
git -C components/tenant-manager checkout origin/main | |
echo -e "Bump tenant-manager component from ${current_sha_short} to ${upstream_sha_short}\n\n" > commitmsg | |
./scripts/describe-component-bump components/tenant-manager ${current_sha} ${upstream_sha} >> commitmsg ||: | |
git -C components/tenant-manager rebase origin/main | |
git add components/tenant-manager | |
git commit -F commitmsg | |
git push -u origin main:main | |
fi | |