Release branch - Publish npm package #122
Workflow file for this run
This file contains hidden or 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 branch - Publish npm package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| npm-tag: | |
| description: 'Npm tag for the release. Use latest for latest stable release, next for latest beta releases and dev for latest alpha releases.' | |
| required: true | |
| type: choice | |
| options: | |
| - dev | |
| - next | |
| - latest | |
| release-flavor: | |
| description: 'Beta release or stable release.' | |
| required: true | |
| type: choice | |
| options: | |
| - stable | |
| - beta | |
| # cancel workflow when a newer version of the workflow is triggered on the same github ref | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| job-inputs: | |
| runs-on: ${{ vars.RUNS_ON }} | |
| permissions: read-all | |
| steps: | |
| - name: Set branch name | |
| id: vars | |
| run: echo "branch=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT | |
| - name: job inputs summary | |
| run: | | |
| echo "### Job Inputs - Review before approving workflow" >> $GITHUB_STEP_SUMMARY | |
| echo "This job has been triggered with the following inputs, review these are correct before approving the npm deployment." >> $GITHUB_STEP_SUMMARY | |
| echo "- release branch: \`${{ steps.vars.outputs.branch }}"\` >> $GITHUB_STEP_SUMMARY | |
| echo "- npm-tag: \`${{ inputs.npm-tag }}"\` >> $GITHUB_STEP_SUMMARY | |
| echo "- release-flavor: \`${{ inputs.release-flavor }}"\` >> $GITHUB_STEP_SUMMARY | |
| publish: | |
| environment: | |
| name: npm | |
| url: https://www.npmjs.com/package/@azure/communication-react | |
| name: Publish release | |
| runs-on: ${{ vars.RUNS_ON }} | |
| permissions: | |
| packages: write | |
| contents: write | |
| id-token: write | |
| steps: | |
| # Check-out repo | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Ensure node version is great enough | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 'lts/*' | |
| # Install dependencies | |
| - name: Install rush | |
| run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") | |
| - name: Install dependencies | |
| run: rush install --max-install-attempts 3 | |
| # Switch flavor to stable when it is release branch | |
| - name: Switch flavor for stable build | |
| # If no param for release flavor, get it from branch name | |
| if: ${{ github.event.inputs.release-flavor == 'stable' }} | |
| run: rush switch-flavor:stable | |
| # Switch flavor to stable when it is release branch | |
| - name: Switch flavor for beta-release build | |
| # If no param for release flavor, get it from branch name | |
| if: ${{ github.event.inputs.release-flavor == 'beta' }} | |
| run: rush switch-flavor:beta-release | |
| # Builds | |
| - name: Build Packages and Samples | |
| run: rush build | |
| # Verify no uncommitted api extractor changes | |
| - name: API Extractor Check | |
| if: ${{ always() }} | |
| run: | | |
| if [[ -z $(git status ${{ matrix.flavor != 'stable' && '**/review/beta/**' || '**/review/stable/**' }}.md -s) ]] | |
| then | |
| echo "Success, no new api changes found." | |
| else | |
| echo "API CHANGES FOUND in ${{ matrix.flavor }} flavor - PLEASE RUN \"${{ matrix.flavor == 'stable' && 'rush switch-flavor:stable &&' || '' }} rush build -t @azure/communication-react\"" | |
| echo "Changes:" | |
| git status ${{ matrix.flavor != 'stable' && '**/review/beta/**' || '**/review/stable/**' }}.md -s | |
| exit 1 | |
| fi | |
| # Run tests | |
| - name: Run Tests | |
| run: rush test | |
| env: | |
| CI: true | |
| ResourceConnectionString: 'endpointString' | |
| EndpointUrl: 'https://endpointUrl' | |
| AdminUserId: 'adminUserId' | |
| AzureBlobStorageConnectionString: 'StorageId' | |
| # Retrieve version to tag and publish release with | |
| - name: Retrieve version from package.json | |
| id: version | |
| run: | | |
| ver=$(jq -r .version packages/communication-react/package.json) | |
| echo version: $ver | |
| echo "version=$ver" >> $GITHUB_OUTPUT | |
| # Clean package.json | |
| - name: Remove devDependencies and beachball from package.json | |
| run: node ../../common/scripts/prepare-package-json.js | |
| working-directory: ./packages/communication-react | |
| # Publish package | |
| - name: Package packages for release | |
| run: npm pack | |
| working-directory: ./packages/communication-react | |
| # Login via OIDC to permit uploading to azure blob store | |
| - name: Azure login | |
| uses: azure/login@v2 | |
| with: | |
| client-id: ${{ secrets.NPM_DEPLOY_AZURE_CLIENT_ID }} | |
| tenant-id: ${{ secrets.NPM_DEPLOY_AZURE_TENANT_ID }} | |
| subscription-id: ${{ secrets.NPM_DEPLOY_AZURE_SUBSCRIPTION_ID }} | |
| # Deploy npm package - this is done by uploading to Azure's SDK blob storage then triggering their partner release pipeline. | |
| # More info: https://dev.azure.com/azure-sdk/internal/_wiki/wikis/internal.wiki/1/Partner-Release-Pipeline | |
| - name: Upload tarball to blob storage | |
| run: az storage blob upload -f "packages/communication-react/release/azure-communication-react-${{ steps.version.outputs.version }}.tgz" -c "drops/azure-communication-services/react/npm/${{ steps.version.outputs.version }}" --account-name azuresdkpartnerdrops --auth-mode login | |
| - name: Trigger alpha package release pipeline | |
| run: az pipelines run --name 'js - partner-release' --org 'https://dev.azure.com/azure-sdk' --project 'internal' --parameters BlobPath=azure-communication-services/react/npm/${{ steps.version.outputs.version }} Tag=${{ github.event.inputs.npm-tag }} | |
| - name: Check if npm package published successfully | |
| run: | | |
| POLL_INTERVAL_SEC=60 # 60 seconds | |
| TIMEOUT_TIME_SEC=3600 # 60 minutes | |
| GET_REQUEST_TIMEOUT_SEC=5 | |
| PACKAGE_NAME="@azure/communication-react" | |
| VERSION="${{ steps.version.outputs.version }}" | |
| start_time=$(date +%s) | |
| while (( $(date +%s) - $start_time < $TIMEOUT_TIME_SEC )); do | |
| response=$(curl --max-time $GET_REQUEST_TIMEOUT_SEC -s -o /dev/null -w "%{http_code}" https://registry.npmjs.org/$PACKAGE_NAME/$VERSION) | |
| echo "Pinging: https://registry.npmjs.org/$PACKAGE_NAME/$VERSION" | |
| echo "responseCode: $response" | |
| if [ $response -eq 200 ]; then | |
| echo "Successfully found npm package" | |
| exit 0 | |
| fi | |
| echo "Sleeping for a bit..." | |
| sleep $POLL_INTERVAL_SEC | |
| done | |
| echo "Failed to find package on the npm registry" | |
| exit 1 | |
| # Push git tags | |
| - name: Create and push git tags | |
| run: | | |
| git tag ${{ steps.version.outputs.version }} | |
| git push --tags | |
| # Upload non-react releases for public preview | |
| - name: Upload Public Preview Release | |
| if: ${{ github.event.inputs.release-flavor == 'beta' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: PublicPreview ${{ steps.version.outputs.version }} | |
| tag_name: PublicPreview/${{ steps.version.outputs.version }} | |
| files: | | |
| ./samples/StaticHtmlComposites/dist/callComposite.js | |
| ./samples/StaticHtmlComposites/dist/outboundCallComposite.js | |
| ./samples/StaticHtmlComposites/dist/chatComposite.js | |
| ./samples/StaticHtmlComposites/dist/callWithChatComposite.js | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |