|
| 1 | +name: Release a npm package |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + package_name: |
| 6 | + description: 'The name of the package' |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + package_folder: |
| 10 | + description: 'The folder of the package to be released, where package.json is in.' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + secrets: |
| 14 | + AZURESDKPARTNERDROPS_URL: |
| 15 | + required: true |
| 16 | + AZURESDKPARTNERDROPS_CLIENT_ID: |
| 17 | + required: true |
| 18 | + AZURESDKPARTNERDROPS_SUBSCRIPTION_ID: |
| 19 | + required: true |
| 20 | + AZURESDKPARTNERDROPS_TENANT_ID: |
| 21 | + required: true |
| 22 | +env: |
| 23 | + NODE_VERSION: '18.x' # set this to the node version to use |
| 24 | + |
| 25 | +jobs: |
| 26 | + check_version: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + needs_release: ${{ steps.compare_versions.outputs.needs_release }} |
| 30 | + release_version: ${{ steps.read_current_version.outputs.current_version }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v3 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Read current version from package.json |
| 37 | + id: read_current_version |
| 38 | + run: | |
| 39 | + current_version=$(jq -r '.version' "${{ inputs.package_folder }}/package.json") |
| 40 | + echo "Current version: $current_version" |
| 41 | + echo "current_version=$current_version" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | + - name: Validate version in change log # Changelog should contain the matching description |
| 44 | + id: changelog_reader |
| 45 | + uses: mindsers/changelog-reader-action@v2 |
| 46 | + with: |
| 47 | + validation_level: none |
| 48 | + version: ${{ steps.read_current_version.outputs.current_version }} |
| 49 | + path: ${{ inputs.package_folder }}/CHANGELOG.md |
| 50 | + - name: Print info from changelog |
| 51 | + id: print |
| 52 | + run: echo ${{steps.changelog_reader.outputs.version}} ${{steps.changelog_reader.outputs.date}} |
| 53 | + |
| 54 | + - name: Needs release |
| 55 | + id: needs_release |
| 56 | + # Needs release when changelog version matches version defined in package.json and release date is set |
| 57 | + if: steps.changelog_reader.outputs.version == steps.read_current_version.outputs.current_version && steps.changelog_reader.outputs.date != '' |
| 58 | + run: | |
| 59 | + echo "needs_release=true" >> $GITHUB_OUTPUT |
| 60 | +
|
| 61 | + - name: Extract version from tag # Further check if version tag exists, if it exists, package already released |
| 62 | + id: tag_version |
| 63 | + if: steps.needs_release.outputs.needs_release == 'true' |
| 64 | + # release tag matchs release/${package_name}/v${version} |
| 65 | + run: | |
| 66 | + TAG_NAME="${GITHUB_REF#refs/tags/}" # Extract tag name from GITHUB_REF |
| 67 | + VERSION=$(echo "$TAG_NAME" | sed -n 's|^release/${{ inputs.package_name }}/v\(.*\)$|\1|p') |
| 68 | + echo "tag_version=$VERSION" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + - name: Compare versions |
| 71 | + id: compare_versions |
| 72 | + if: steps.needs_release.outputs.needs_release == 'true' && steps.tag_version.outputs.tag_version != steps.read_current_version.outputs.current_version |
| 73 | + run: | |
| 74 | + echo "needs_release=true" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + build: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: check_version |
| 79 | + if: ${{ needs.check_version.outputs.needs_release == 'true' }} |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v3 |
| 82 | + with: |
| 83 | + fetch-depth: 0 |
| 84 | + - name: Set up Node.js |
| 85 | + uses: actions/setup-node@v3 |
| 86 | + with: |
| 87 | + node-version: ${{ env.NODE_VERSION }} |
| 88 | + cache: 'npm' |
| 89 | + - name: Install dependencies |
| 90 | + run: npm install -g yarn |
| 91 | + - name: Pack the package |
| 92 | + id: pack_package |
| 93 | + run: | |
| 94 | + pushd sdk/server-proxies |
| 95 | + yarn |
| 96 | + popd |
| 97 | + pushd ${{ inputs.package_folder }} |
| 98 | + yarn |
| 99 | + yarn build |
| 100 | + yarn pack |
| 101 | + for file in $(find . -type f -name '*.tgz'); do |
| 102 | + path="./${{ inputs.package_folder }}/${file#./}" |
| 103 | + echo "packageName=${file#./}" >> $GITHUB_OUTPUT |
| 104 | + echo "packagePath=$path" >> $GITHUB_OUTPUT |
| 105 | + done |
| 106 | + popd |
| 107 | + shell: bash |
| 108 | + - name: Publish Artifacts |
| 109 | + uses: actions/upload-artifact@v2 |
| 110 | + with: |
| 111 | + name: ${{ inputs.package_name }} |
| 112 | + path: ${{ steps.pack_package.outputs.packagePath }} |
| 113 | + |
| 114 | + deploy: |
| 115 | + runs-on: ubuntu-latest |
| 116 | + needs: [ check_version, build ] |
| 117 | + environment: Cloud |
| 118 | + steps: |
| 119 | + - name: Download Artifacts |
| 120 | + uses: actions/download-artifact@v4 |
| 121 | + with: |
| 122 | + name: ${{ inputs.package_name }} |
| 123 | + download-path: ${{ inputs.package_name }} |
| 124 | + - name: 'Az CLI login' |
| 125 | + uses: azure/login@v2 |
| 126 | + with: |
| 127 | + client-id: ${{ secrets.AZURESDKPARTNERDROPS_CLIENT_ID }} |
| 128 | + tenant-id: ${{ secrets.AZURESDKPARTNERDROPS_TENANT_ID }} |
| 129 | + subscription-id: ${{ secrets.AZURESDKPARTNERDROPS_SUBSCRIPTION_ID }} |
| 130 | + - name: AzCopy to shared blob |
| 131 | + env: |
| 132 | + BUILDNUMBER: ${{ steps.read_current_version.outputs.current_version }} |
| 133 | + AZURESDKPARTNERDROPS_URL: ${{secrets.AZURESDKPARTNERDROPS_URL}} |
| 134 | + run: | |
| 135 | + azcopy copy ${{ inputs.package_name }} "$AZURESDKPARTNERDROPS_URL/azure-webpubsub/${{ inputs.package_name }}/${{ needs.check_version.outputs.release_version }}/" |
| 136 | +
|
| 137 | +
|
0 commit comments