Skip to content

Commit

Permalink
Update release_socketio.yml (#771)
Browse files Browse the repository at this point in the history
* Update release_socketio.yml

* Update release_socketio.yml

* Extract to workflow

* Update release_socketio.yml
  • Loading branch information
vicancy authored Jul 10, 2024
1 parent 2af5710 commit fb7350e
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 93 deletions.
102 changes: 9 additions & 93 deletions .github/workflows/release_socketio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,99 +8,15 @@ on:
- '.github/workflows/release_socketio.yml'
- 'sdk/webpubsub-socketio-extension/package.json'
- 'sdk/webpubsub-socketio-extension/CHANGELOG.md'

env:
NODE_VERSION: '18.x' # set this to the node version to use

jobs:
build:
runs-on: ubuntu-latest
environment: Cloud
outputs:
version: ${{ steps.read_current_version.outputs.current_version }}
version_changed: ${{ steps.compare_versions.outputs.version_changed }}
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' sdk/webpubsub-socketio-extension/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: sdk/webpubsub-socketio-extension/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
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
id: tag_version
if: steps.needs_release.outputs.needs_release == 'true'
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}" # Extract tag name from GITHUB_REF
VERSION=$(echo "$TAG_NAME" | sed -n 's|^release/webpubsub-socketio-extension/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 "version_changed=true" >> $GITHUB_OUTPUT
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
if: steps.compare_versions.outputs.version_changed == 'true'

- name: Install dependencies
run: npm install -g yarn
if: steps.compare_versions.outputs.version_changed == 'true'

- name: Pack SocketIO package
id: socketio
if: steps.compare_versions.outputs.version_changed == 'true'
run: |
pushd sdk/server-proxies
yarn
popd
pushd sdk/webpubsub-socketio-extension
yarn
yarn build
yarn pack
for file in $(find . -type f -name '*.tgz'); do
path="./sdk/webpubsub-socketio-extension/${file#./}"
echo "packageName=${file#./}" >> $GITHUB_OUTPUT
echo "packagePath=$path" >> $GITHUB_OUTPUT
done
popd
shell: bash
- name: Publish SocketIO Artifacts
if: steps.compare_versions.outputs.version_changed == 'true'
uses: actions/upload-artifact@v2
with:
name: socketio package
path: ${{ steps.socketio.outputs.packagePath }}
- name: 'Az CLI login'
if: steps.compare_versions.outputs.version_changed == 'true'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURESDKPARTNERDROPS_CLIENT_ID }}
tenant-id: ${{ secrets.AZURESDKPARTNERDROPS_TENANT_ID }}
subscription-id: ${{ secrets.AZURESDKPARTNERDROPS_SUBSCRIPTION_ID }}
- name: AzCopy to shared blob
if: steps.compare_versions.outputs.version_changed == 'true'
env:
BUILDNUMBER: ${{ steps.read_current_version.outputs.current_version }}
run: |
azcopy copy ${{ steps.socketio.outputs.packagePath }} "$URL/azure-webpubsub/sio/$BUILDNUMBER/"
uses: ./.github/workflows/workflow-call-release-package.yml
secrets:
AZURESDKPARTNERDROPS_URL: ${{ secrets.AZURESDKPARTNERDROPS_URL }}
AZURESDKPARTNERDROPS_CLIENT_ID: ${{ secrets.AZURESDKPARTNERDROPS_CLIENT_ID }}
AZURESDKPARTNERDROPS_SUBSCRIPTION_ID: ${{ secrets.AZURESDKPARTNERDROPS_SUBSCRIPTION_ID }}
AZURESDKPARTNERDROPS_TENANT_ID: ${{ secrets.AZURESDKPARTNERDROPS_TENANT_ID }}
with:
package_name: webpubsub-socketio-extension
package_folder: sdk/webpubsub-socketio-extension
137 changes: 137 additions & 0 deletions .github/workflows/workflow-call-release-package.yml
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 }}/"

0 comments on commit fb7350e

Please sign in to comment.