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 a npm package | |
on: | |
workflow_call: | |
inputs: | |
package_name: | |
description: 'The name of the package' | |
required: true | |
type: string | |
package_folder: | |
description: 'The folder of the package to be released, where package.json is in.' | |
required: true | |
type: string | |
secrets: | |
AZURESDKPARTNERDROPS_URL: | |
required: true | |
AZURESDKPARTNERDROPS_CLIENT_ID: | |
required: true | |
AZURESDKPARTNERDROPS_SUBSCRIPTION_ID: | |
required: true | |
AZURESDKPARTNERDROPS_TENANT_ID: | |
required: true | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read | |
env: | |
NODE_VERSION: '18.x' # set this to the node version to use | |
jobs: | |
check_version: | |
runs-on: ubuntu-latest | |
outputs: | |
needs_release: ${{ steps.compare_versions.outputs.needs_release }} | |
release_version: ${{ steps.read_current_version.outputs.current_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Read current version from package.json | |
id: read_current_version | |
run: | | |
current_version=$(jq -r '.version' "${{ inputs.package_folder }}/package.json") | |
echo "Current version: $current_version" | |
echo "current_version=$current_version" >> $GITHUB_OUTPUT | |
- name: Validate version in change log # Changelog should contain the matching description | |
id: changelog_reader | |
uses: mindsers/changelog-reader-action@v2 | |
with: | |
validation_level: none | |
version: ${{ steps.read_current_version.outputs.current_version }} | |
path: ${{ inputs.package_folder }}/CHANGELOG.md | |
- name: Print info from changelog | |
id: print | |
run: echo ${{steps.changelog_reader.outputs.version}} ${{steps.changelog_reader.outputs.date}} | |
- name: Needs release | |
id: needs_release | |
# Needs release when changelog version matches version defined in package.json and release date is set | |
if: steps.changelog_reader.outputs.version == steps.read_current_version.outputs.current_version && steps.changelog_reader.outputs.date != '' | |
run: | | |
echo "needs_release=true" >> $GITHUB_OUTPUT | |
- name: Extract version from tag # Further check if version tag exists, if it exists, package already released | |
id: tag_version | |
if: steps.needs_release.outputs.needs_release == 'true' | |
# release tag matchs release/${package_name}/v${version} | |
run: | | |
TAG_NAME="${GITHUB_REF#refs/tags/}" # Extract tag name from GITHUB_REF | |
VERSION=$(echo "$TAG_NAME" | sed -n 's|^release/${{ inputs.package_name }}/v\(.*\)$|\1|p') | |
echo "tag_version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Compare versions | |
id: compare_versions | |
if: steps.needs_release.outputs.needs_release == 'true' && steps.tag_version.outputs.tag_version != steps.read_current_version.outputs.current_version | |
run: | | |
echo "needs_release=true" >> $GITHUB_OUTPUT | |
build-deploy: | |
runs-on: ubuntu-latest | |
needs: check_version | |
environment: Cloud | |
if: ${{ needs.check_version.outputs.needs_release == 'true' }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm install -g yarn | |
- name: Pack the package | |
id: pack_package | |
# TODO: how to setup yarn install in caller workflow | |
run: | | |
pushd sdk/server-proxies | |
yarn | |
popd | |
pushd tools/awps-tunnel/client | |
yarn | |
popd | |
pushd ${{ inputs.package_folder }} | |
yarn | |
yarn build | |
yarn pack | |
for file in $(find . -type f -name '*.tgz'); do | |
path="./${{ inputs.package_folder }}/${file#./}" | |
echo "packageName=${file#./}" >> $GITHUB_OUTPUT | |
echo "packagePath=$path" >> $GITHUB_OUTPUT | |
done | |
popd | |
shell: bash | |
- name: Publish Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ inputs.package_name }} | |
path: ${{ steps.pack_package.outputs.packagePath }} | |
- name: 'Az CLI login' | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURESDKPARTNERDROPS_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURESDKPARTNERDROPS_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURESDKPARTNERDROPS_SUBSCRIPTION_ID }} | |
- name: 'AzCopy to shared blob' | |
run: | | |
az storage blob upload --auth-mode login -f ${{ steps.pack_package.outputs.packagePath }} --blob-url "${{ secrets.AZURESDKPARTNERDROPS_URL }}/azure-webpubsub/${{ inputs.package_name }}/${{ needs.check_version.outputs.release_version }}/${{ steps.pack_package.outputs.packageName }}" | |
post-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Approval after release for adding release tag | |
id: approval | |
uses: reviewdog/action-yamllint@v1 | |
with: | |
approval: true | |
- name: TODO-Create and push release tag |