-
Notifications
You must be signed in to change notification settings - Fork 87
138 lines (131 loc) · 5.16 KB
/
workflow-call-release-package.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
permissions:
id-token: write # This is required for requesting the JWT
contents: read
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@v4
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-deploy:
runs-on: ubuntu-latest
needs: check_version
environment: Cloud
if: ${{ needs.check_version.outputs.needs_release == 'true' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm install -g yarn
- name: Pack the package
id: pack_package
# TODO: how to setup yarn install in caller workflow
run: |
pushd sdk/server-proxies
yarn
popd
pushd tools/awps-tunnel/client
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@v4
with:
name: ${{ inputs.package_name }}
path: ${{ steps.pack_package.outputs.packagePath }}
- 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'
run: |
az storage blob upload --auth-mode login -f ${{ steps.pack_package.outputs.packagePath }} --blob-url "${{ secrets.AZURESDKPARTNERDROPS_URL }}/azure-webpubsub/${{ inputs.package_name }}/${{ needs.check_version.outputs.release_version }}/${{ steps.pack_package.outputs.packageName }}"
post-deploy:
runs-on: ubuntu-latest
steps:
- name: Approval after release for adding release tag
id: approval
uses: reviewdog/action-yamllint@v1
with:
approval: true
- name: TODO-Create and push release tag