-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update release_socketio.yml * Update release_socketio.yml * Extract to workflow * Update release_socketio.yml
- Loading branch information
Showing
2 changed files
with
146 additions
and
93 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
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 | ||
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@v3 | ||
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: | ||
runs-on: ubuntu-latest | ||
needs: check_version | ||
if: ${{ needs.check_version.outputs.needs_release == 'true' }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: 'npm' | ||
- name: Install dependencies | ||
run: npm install -g yarn | ||
- name: Pack the package | ||
id: pack_package | ||
run: | | ||
pushd sdk/server-proxies | ||
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@v2 | ||
with: | ||
name: ${{ inputs.package_name }} | ||
path: ${{ steps.pack_package.outputs.packagePath }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [ check_version, build ] | ||
environment: Cloud | ||
steps: | ||
- name: Download Artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.package_name }} | ||
download-path: ${{ inputs.package_name }} | ||
- 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 | ||
env: | ||
BUILDNUMBER: ${{ steps.read_current_version.outputs.current_version }} | ||
AZURESDKPARTNERDROPS_URL: ${{secrets.AZURESDKPARTNERDROPS_URL}} | ||
run: | | ||
azcopy copy ${{ inputs.package_name }} "$AZURESDKPARTNERDROPS_URL/azure-webpubsub/${{ inputs.package_name }}/${{ needs.check_version.outputs.release_version }}/" | ||