This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
Nightly alpha package release #10
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: Nightly alpha package release | |
on: | |
schedule: | |
# minute 0, hour 0 UTC (which is 6pm PST/5pm PDT), any day of month, any month, any day of the week | |
# if we want to support only Mon - Fri we need to change the check how we look for new changes. Currently we | |
# check for any new changes in the last 24 hours regardless of day) | |
- cron: '0 0 * * *' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# 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: | |
checkForChanges: | |
name: Check for new changes | |
outputs: | |
hasChanged: ${{ steps.checkChange.outputs.hasChanged }} | |
runs-on: ubuntu-latest | |
steps: | |
# Check-out repo | |
- uses: actions/checkout@v3 | |
# Check if any changes have been pushed to main since last release | |
- name: Check latest commit age | |
id: checkChange | |
# Here we query the github rest api for the commits, use jq (json parser) to grab the first commit and put contents into $HOME/commit.json | |
# Note: we ignore commits made by the bot account that commits the auto version bump changes. | |
# Then get the timestamp date for the first commit and check if it was over a day old. | |
run: | | |
curl -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -sL https://api.github.com/repos/${{ github.repository }}/commits | jq -r '[.[] | select(.author.login != "github-action-bot")][0]' > $HOME/commit.json | |
commitdate=$(jq -r '.commit.author.date' $HOME/commit.json) | |
commiturl=$(jq -r '.url' $HOME/commit.json) | |
echo Last commit: $commiturl | |
echo Last commit date \(UTC\): $commitdate | |
timestamp=$(date --utc -d "$commitdate" +%s) | |
echo Commit timestamp: $timestamp | |
currentTimestamp=$(date --utc +%s) | |
echo Current timestamp: $currentTimestamp | |
days=$(( ($currentTimestamp - $timestamp ) / 86400 )) | |
echo Days since last commit: $days | |
if [ $days = "0" ]; then | |
echo "hasChanged=true" >> $GITHUB_OUTPUT | |
else | |
echo "hasChanged=false" >> $GITHUB_OUTPUT | |
fi | |
release: | |
name: Create alpha releases | |
needs: checkForChanges | |
if: needs.checkForChanges.outputs.hasChanged == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
# Check-out repo | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Ensure node version is great enough | |
- name: Use Node.js v18.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
# Try get node_modules from cache | |
- name: Restore node_modules from cache | |
uses: actions/cache@v3 | |
with: | |
path: common/temp/pnpm-store | |
key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} | |
# Install dependencies | |
- name: Install rush | |
run: npm install -g @microsoft/[email protected] | |
- name: Install dependencies | |
run: rush install --max-install-attempts 3 | |
# Get datetime | |
- name: Get datetime for alpha release name | |
id: datetime | |
run: | | |
echo "datetime=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT | |
# Bump alpha package versions | |
- name: Bump alpha package versions | |
run: node common/scripts/bump-alpha-versions.js ${{ steps.datetime.outputs.datetime }} | |
- name: Synchronize package version reported to telemetry | |
run: node common/scripts/sync-telemetry-package-version | |
# Important to check version consistency again after bumping versions. | |
- name: Ensure all package versions are consistent | |
run: rush ensure-consistent-versions | |
# Alpha version run latest | |
- name: Force build flavor to `beta` | |
run: node ./common/scripts/force-build-flavor.mjs beta | |
# Build packages | |
- name: Build @azure/communication-react package | |
run: rush build -t @azure/communication-react | |
# Test Packages | |
- name: Test @azure/communication-react package | |
run: rush test -t @azure/communication-react | |
# Retrieve new version to tag and publish release with | |
- name: Retrieve new version from package.json | |
id: version | |
run: | | |
ver=$(jq -r .version packages/communication-react/package.json) | |
echo version: $ver | |
echo "version=$ver" >> $GITHUB_OUTPUT | |
# Push git tags | |
- name: Create and push git tags | |
run: | | |
git tag ${{ steps.version.outputs.version }} | |
git push --tags | |
# Clean package.json | |
- name: Remove scripts, devDependencies, and beachball from package.json | |
run: node ./common/scripts/preparePackageJSON.js | |
working-directory: ./packages/communication-react | |
# Publish package | |
- name: Package alpha packages for release | |
run: npm pack | |
working-directory: ./packages/communication-react | |
# 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 | |
uses: azure/CLI@v1 | |
with: | |
inlineScript: | | |
az login --service-principal -u ${{ secrets.AZURESDKPARTNERDROPS_CLIENT_ID }} -p ${{ secrets.AZURESDKPARTNERDROPS_SERVICE_PRINCIPAL_KEY }} --tenant ${{ secrets.AZURESDKPARTNERDROPS_TENANT_ID }} | |
az extension add --name storage-preview | |
az storage azcopy blob upload -s "packages/communication-react/release/*" -c "drops/azure-communication-services/react/npm/${{ steps.version.outputs.version }}" --account-name azuresdkpartnerdrops | |
- name: Trigger alpha package release pipeline | |
uses: Azure/[email protected] | |
with: | |
azure-devops-project-url: 'https://dev.azure.com/azure-sdk/internal' | |
azure-pipeline-name: 'azuresdkpartnerdrops to npm' | |
azure-devops-token: '${{ secrets.AZURE_SDK_RELEASE_PIPELINE_DEVOPS_TOKEN }}' | |
azure-pipeline-variables: '{"accessLevel": "public", "BlobPath": "azure-communication-services/react/npm/${{ steps.version.outputs.version }}", "registry": "https://registry.npmjs.org/", "skipDiff": "False", "tag": "dev"}' | |
- name: Check if npm package published successfully | |
run: node common/scripts/poll-npm-package-published.mjs ${{ steps.version.outputs.version }} | |
check_failure: | |
runs-on: ubuntu-latest | |
needs: release | |
if: failure() | |
name: Create GitHub issue on failure | |
steps: | |
# Failure of this action indicates a problem with our infrastructure. | |
# Always file a GitHub issue to alert the OCE of the problem. | |
- name: Create GitHub issue | |
id: create-issue | |
run: | | |
# check for an issue that is already open | |
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/search/issues?q=org:Azure+repo:communication-ui-library+label:NIGHTLY_CD_FAILURE+state:open > $HOME/open_issues.json | |
issue_count=$(jq -r '.total_count' $HOME/open_issues.json) | |
if [ $issue_count -gt 0 ]; then | |
echo "No need to create new issue, one already exists" | |
else | |
curl -X POST -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/Azure/communication-ui-library/issues -d '{"title":"Nightly workflow to release alpha package failed", "body": "Please investigate: https://github.com/Azure/communication-ui-library/actions/runs/${{ github.run_id }}", "labels":["NIGHTLY_CD_FAILURE", "status:triage"]}' | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |