Create release and publish to drop #82
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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: Create release and publish to drop | |
permissions: write-all | |
on: workflow_dispatch | |
jobs: | |
test: | |
name: Run tests | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [macos-12, windows-latest, ubuntu-latest] | |
node-version: [18.x, 20.x] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- run: npm ci | |
- run: npm test | |
packageAndRelease: | |
needs: [ test ] | |
name: Package / tag / release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Use Node.js 18.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
- run: npm ci | |
- run: npm run build | |
- run: npm pack | |
- name: Upload | |
uses: actions/upload-artifact@v2 | |
with: | |
name: package | |
path: "*.tgz" | |
- name: Get package version | |
run: echo "NPM_PACKAGE_VERSION=$(jq -r ".version" package.json)" >> $GITHUB_ENV | |
- name: Get package path | |
run: echo "NPM_PACKAGE_PATH=$(ls *.tgz)" >> $GITHUB_ENV | |
- name: Get commit SHA | |
run: echo "GIT_COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Create tag | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/v${{ env.NPM_PACKAGE_VERSION }}", | |
sha: "${{ env.GIT_COMMIT_SHA }}" | |
}) | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.NPM_PACKAGE_VERSION }} | |
release_name: v${{ env.NPM_PACKAGE_VERSION }} | |
draft: true | |
prerelease: true | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.NPM_PACKAGE_PATH }} | |
asset_name: ${{ env.NPM_PACKAGE_PATH }} | |
asset_content_type: application/tar+gzip | |
copy: | |
name: "Copy to drop" | |
needs: [ packageAndRelease ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: package | |
# Login via OIDC to permit uploading to azure drops blob store | |
- name: 'Az login' | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.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 to drop | |
run: | | |
ls -la | |
PACKAGE_ID=`echo $(ls *.tgz) | sed -e 's/\.tgz$//'` | |
echo $PACKAGE_ID | |
az storage blob upload -n azure-staticwebapps/npm/$PACKAGE_ID/$(ls *.tgz) -c drops -f $(ls *.tgz) --account-name azuresdkpartnerdrops --auth-mode login |