Skip to content
Snippets Groups Projects
Unverified Commit 042213e3 authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Automate SDK release version numbers (#48838) (#48940)


* Automate npm version

* Make troubleshooting SDK release process easier

* Fix quote situation

* Allow deploying SDK to different branches at the same time

Because they won't be in conflict with each other

* Make checkout a bit faster

* Remove unnecessary console.log



* Tidy up `jq` command



* Tidy up multiple GitHub actions summary log



---------

Co-authored-by: default avatarMahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>
Co-authored-by: default avatarPhoomparin Mano <poom@metabase.com>
parent 9309dfe3
Branches
Tags
No related merge requests found
......@@ -4,32 +4,88 @@ on:
workflow_dispatch:
inputs:
# TODO: Add a version validation, so the workflow won't fail when publishing to npm
sdk_version:
description: "SDK version (e.g. 0.1.3)"
type: string
required: true
git_ref:
description: "A git commit hash that will be used to build the SDK"
type: string
branch:
description: "Branch we want to release the SDK from"
type: choice
required: true
default: "master"
options:
- master
- release-x.51.x
concurrency:
# We want to ensure only one job is running at a time because
# We want to ensure only one job is running at a time per branch because
# there could be a conflict when updating the readme file.
group: ${{ github.workflow }}
group: ${{ github.workflow }}-${{ inputs.branch }}
cancel-in-progress: true
jobs:
workflow-summary:
name: Log inputs
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Generate workflow summary
run: |
tee -a $GITHUB_STEP_SUMMARY << EOF
**Inputs:**
- \`branch\`: ${{ inputs.branch }}
triggered by: @${{ github.event.sender.login }}
EOF
determine-version:
name: Determine SDK version
runs-on: ubuntu-22.04
timeout-minutes: 20
outputs:
sdk_version: ${{ steps.new-sdk-version.outputs.result }}
steps:
- name: Check out the code using the provided branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Get current SDK version
id: current-sdk-version
run: |
VERSION=$(jq -r .version ./enterprise/frontend/src/embedding-sdk/package.template.json)
echo "::set-output name=sdk_current_version::$VERSION"
- name: Get next SDK patch version
id: new-sdk-version
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const currentVersion = "${{ steps.current-sdk-version.outputs.sdk_current_version }}";
const versionParts = currentVersion.split(".");
versionParts[versionParts.length - 1] = parseInt(versionParts.at(-1)) + 1;
const newVersion = versionParts.join(".");
return newVersion
- name: Append workflow summary
run: |
tee -a $GITHUB_STEP_SUMMARY << EOF
**Derived inputs:**
- \`current_version\`: "${{ steps.current-sdk-version.outputs.sdk_current_version }}"
- \`next_version\`: "${{ steps.new-sdk-version.outputs.result }}"
EOF
check-git-tag:
needs: determine-version
runs-on: ubuntu-22.04
timeout-minutes: 20
env:
tag: embedding-sdk-${{ inputs.sdk_version }}
tag: embedding-sdk-${{ needs.determine-version.outputs.sdk_version }}
steps:
- name: Check out the code using the provided ref
- name: Check out the code using the provided branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
ref: ${{ inputs.branch }}
fetch-depth: 0
fetch-tags: true
......@@ -48,10 +104,10 @@ jobs:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- name: Check out the code using the provided ref
- name: Check out the code using the provided branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
ref: ${{ inputs.branch }}
- name: Prepare front-end environment
uses: ./.github/actions/prepare-frontend
......@@ -65,14 +121,14 @@ jobs:
run: yarn embedding-sdk:test-unit
build-sdk:
needs: test
needs: [test, determine-version]
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- name: Check out the code using the provided ref
- name: Check out the code using the provided branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
ref: ${{ inputs.branch }}
fetch-depth: 0
fetch-tags: true
......@@ -84,14 +140,10 @@ jobs:
with:
m2-cache-key: "release-sdk"
- name: Update readme
run: |
./bin/embedding-sdk/release_utils.bash update_readme ${{ inputs.sdk_version }}
- name: Bump published npm package version
# NOTE: this should happen before "Build SDK bundle" as we inject SDK version into the code during build step
run: |
./bin/embedding-sdk/release_utils.bash update_package_json_template ${{ inputs.sdk_version }}
./bin/embedding-sdk/release_utils.bash update_package_json_template ${{ needs.determine-version.outputs.sdk_version }}
- name: Update changelog
run: |
......@@ -116,15 +168,17 @@ jobs:
path: ./changelog-diff
publish-npm:
needs: build-sdk
needs: [build-sdk, determine-version]
runs-on: ubuntu-22.04
timeout-minutes: 20
env:
sdk_version: ${{ needs.determine-version.outputs.sdk_version }}
steps:
- name: Check out master to prepare for a SDK version bump PR
- name: Check out branch to prepare for a SDK version bump PR
uses: actions/checkout@v4
with:
# when we created version update PR, it would only have diff from 2 files SDK readme and SDK package.json template
ref: master
ref: ${{ inputs.branch}}
- name: Setup git user
run: |
......@@ -133,11 +187,11 @@ jobs:
- name: Update readme
run: |
bash ./bin/embedding-sdk/release_utils.bash update_readme ${{ inputs.sdk_version }}
bash ./bin/embedding-sdk/release_utils.bash update_readme ${{ env.sdk_version }}
- name: Bump published npm package version
run: |
bash ./bin/embedding-sdk/release_utils.bash update_package_json_template ${{ inputs.sdk_version }}
bash ./bin/embedding-sdk/release_utils.bash update_package_json_template ${{ env.sdk_version }}
- name: Retrieve SDK changelog diff
uses: actions/download-artifact@v4
......@@ -151,13 +205,13 @@ jobs:
- name: Create a PR updating readme + published version, and changelog (using GitHub Metabase Automation account)
run: |
git checkout -b update-sdk-version-${{ inputs.sdk_version }}
git commit -a -m 'Update Readme version references and published npm version to ${{ inputs.sdk_version }}'
git checkout -b update-sdk-version-${{ env.sdk_version }}
git commit -a -m 'Update Readme version references and published npm version to ${{ env.sdk_version }}'
git push origin HEAD
gh pr create --base master\
gh pr create --base ${{ inputs.branch }}\
--assignee "${GITHUB_ACTOR}"\
--title "Update SDK version to ${{ inputs.sdk_version }}"\
--body "Update Readme version references and published npm package version to ${{ inputs.sdk_version }}"
--title "Update SDK version to ${{ env.sdk_version }}"\
--body "Update Readme version references and published npm package version to ${{ env.sdk_version }}"
env:
GH_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
......@@ -198,16 +252,16 @@ jobs:
npm publish
git-tag:
needs: publish-npm
needs: [publish-npm, determine-version]
runs-on: ubuntu-22.04
timeout-minutes: 20
env:
tag: embedding-sdk-${{ inputs.sdk_version }}
tag: embedding-sdk-${{ needs.determine-version.outputs.sdk_version }}
steps:
- name: Check out the code using the provided ref
- name: Check out the code using the provided branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
ref: ${{ inputs.branch }}
# Lightweight tags don't need committer name and email
- name: Create a new git tag
......
summary 0 → 100644
**Inputs:**
- : branch
triggered by: userName
**Inputs:**
- `branch`: branch
triggered by: userName
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment