Release & Publish to NPM #152
Workflow file for this run
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: Release & Publish to NPM | |
on: | |
workflow_dispatch: | |
inputs: | |
increment: | |
type: choice | |
description: Select increment | |
options: | |
- patch | |
- minor | |
- major | |
- beta | |
beta_version: | |
type: string | |
description: Type version if beta increment is selected | |
package: | |
type: choice | |
description: Select package | |
options: | |
- '@inworld/web-core' | |
- '@inworld/web-threejs' | |
env: | |
AUTH_SERVICE_ACCOUNT: [email protected] | |
AUTH_IDENTITY_PROVIDER: projects/678423885598/locations/global/workloadIdentityPools/github-devops-pool/providers/github-prvdr | |
jobs: | |
github-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set version | |
run: echo "VERSION=${{ inputs.increment}}" >> $GITHUB_ENV | |
- name: Set beta version | |
run: echo "VERSION=${{ inputs.beta_version }}" >> $GITHUB_ENV | |
if: inputs.beta_version != '' | |
- name: Echo version & package | |
run: echo "${{ env.VERSION }}" "${{ inputs.package }}" | |
- name: Set ref | |
run: echo "REF=main" >> $GITHUB_ENV | |
if: inputs.beta_version == '' | |
- name: Set config | |
run: echo "CONFIG=-c .release-it.prerelease.json" >> $GITHUB_ENV | |
if: inputs.beta_version != '' | |
- name: Set git user | |
run: git config --global user.email "[email protected]" && git config --global user.name "CI-inworld" | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ env.REF }} | |
ssh-key: ${{ secrets.GH_SERVICE_ACCOUNT_SSH_KEY }} | |
- name: Run build | |
uses: ./.github/actions/build_package | |
- name: Bump version | |
run: | | |
npx yarn workspace ${{ inputs.package }} release:bump ${{ env.VERSION }} ${{ env.CONFIG }} --ci | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
npm-release: | |
runs-on: ubuntu-latest | |
needs: [github-release] | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ env.REF }} | |
- name: Pull latest changes | |
run: git pull | |
- name: Run build | |
uses: ./.github/actions/build_package | |
with: | |
mode: 'prod' | |
- name: Set Tag | |
run: echo "TAG=--tag=beta" >> $GITHUB_ENV | |
if: inputs.beta_version != '' | |
- run: echo "npmAuthToken:" "${{ secrets.NPM_TOKEN }}" >> .yarnrc.yml | |
- name: Publish to npm | |
run: npx yarn workspace ${{ inputs.package }} release:publish ${{ env.TAG }} | |
minify-and-upload: | |
runs-on: [self-hosted, linux, x64, kubernetes, ephemeral] | |
needs: [npm-release] | |
if: inputs.beta_version == '' | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set TAG as the latest one | |
run: echo "TAG=refs/tags/`echo $(git describe --tags --match="${{ inputs.package }}*" --abbrev=0)`" >> $GITHUB_ENV | |
- name: Minify and upload | |
uses: ./.github/actions/upload_minified_version | |
with: | |
package: ${{ inputs.package }} | |
tag: ${{ env.TAG }} | |
env: | |
AUTH_SERVICE_ACCOUNT: ${{ env.AUTH_SERVICE_ACCOUNT }} | |
AUTH_IDENTITY_PROVIDER: ${{ env.AUTH_IDENTITY_PROVIDER }} | |
release-notification: | |
runs-on: [self-hosted, kubernetes, nodocker] | |
needs: [github-release, npm-release] | |
# always runs even if previous tasks are not successful | |
if: always() | |
steps: | |
- name: Checkout source code | |
if: needs.npm-release.result == 'success' | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
- name: Build version path | |
if: needs.npm-release.result == 'success' | |
run: | | |
echo "path=require('./packages${{ inputs.package }}/package.json').version" | sed 's/@inworld//g' >> $GITHUB_OUTPUT | |
id: extract-version-path | |
- name: Extract version | |
if: needs.npm-release.result == 'success' | |
run: | | |
echo "version=$(node -e "console.log(${{ steps.extract-version-path.outputs.path }})")" >> $GITHUB_OUTPUT | |
id: extract-version | |
- name: Extract changelog | |
if: needs.npm-release.result == 'success' | |
run: | | |
echo "changelog=./packages${{ inputs.package }}/CHANGELOG.md" | sed 's/@inworld//g' >> $GITHUB_OUTPUT | |
id: extract-changelog | |
- name: Extract release notes | |
if: needs.npm-release.result == 'success' | |
id: extract-release-notes | |
uses: ffurrer2/extract-release-notes@v1 | |
with: | |
changelog_file: ${{ steps.extract-changelog.outputs.changelog }} | |
- name: Slack Notification | |
if: always() | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.INTEGRATIONS_SLACK_WEBHOOK }} | |
SLACK_COLOR: ${{ contains(needs.*.result, 'failure') && 'danger' || 'good' }} | |
SLACK_TITLE: Release ${{ contains(needs.*.result, 'failure') && 'failure' || steps.extract-version.outputs.version }} | |
SLACK_MESSAGE: ${{ contains(needs.*.result, 'failure') && ':x:' || steps.extract-release-notes.outputs.release_notes }} | |
SLACK_FOOTER: '-Web SDK-' |