-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (129 loc) · 6.21 KB
/
publish.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
139
140
141
142
143
144
145
146
147
name: Publish
on:
workflow_dispatch:
inputs:
package:
type: choice
description: 'choose package'
default: 'iris-web-rtc'
required: true
options:
- iris-web-rtc
- iris-web-rtm
cdn:
description: 'upload to cdn'
default: true
type: boolean
jobs:
release-it:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup
uses: ./.github/actions/setup
- name: Setup Dependencies and Build
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm install
pnpm run build
RTC_PACKAGE_PATH=$(ls packages/rtc/dist | awk -F/ '{print $NF}')
echo "RTC_PACKAGE_PATH=$RTC_PACKAGE_PATH" >> $GITHUB_ENV
RTC_FAKE_PACKAGE_PATH=$(ls packages/fake/rtc/dist | awk -F/ '{print $NF}')
echo "RTC_FAKE_PACKAGE_PATH=$RTC_FAKE_PACKAGE_PATH" >> $GITHUB_ENV
- name: Setup NPM auth token
run: |
npm set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_TOKEN }}
- name: Config Git
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
- name: Get Package Info
if: ${{ inputs.package == 'iris-web-rtc' }}
run: |
version=$(node -p "require('./packages/rtc/package.json').version")
echo "version=${version}" >> $GITHUB_ENV
- name: Get Package Info
if: ${{ inputs.package == 'iris-web-rtm' }}
run: |
version=$(node -p "require('./packages/rtm/package.json').version")
echo "version=${version}" >> $GITHUB_ENV
- name: Check if release exists 🚀
id: check-if-release-exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Current tag = v${{ env.version }}"
RELEASE_TAG="v${{ env.version }}"
if [[ "${{ inputs.release-tag }}" != "" ]]; then
echo "Setting release tag to check to ${{ inputs.release-tag }}"
RELEASE_TAG="${{ inputs.release-tag }}"
fi
set +e
if [[ "$(gh release view $RELEASE_TAG 2>&1)" == "release not found" ]]; then
echo "Release not found."
echo "release-exists=0" >> $GITHUB_OUTPUT
else
echo "Release found."
echo "release-exists=1" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Update CHANGELOG.md and Create Release
if: ${{ steps.check-if-release-exists.outputs.release-exists == 0 }}
run: |
pnpm release ${{ env.version }} --ci --npm.allowSameVersion --github.assets=./packages/rtc/dist/${{ env.RTC_PACKAGE_PATH }} --github.assets=./packages/fake/rtc/dist/${{ env.RTC_FAKE_PACKAGE_PATH }}
- name: Get Release ID
id: get_release
if: ${{ steps.check-if-release-exists.outputs.release-exists == 1 }}
run: |
release_id=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ env.version }} | jq '.id')
echo "RELEASE_ID=$release_id" >> $GITHUB_ENV
- name: Delete All Assets
if: ${{ steps.check-if-release-exists.outputs.release-exists == 1 }}
run: |
assets=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets)
for asset_id in $(echo "$assets" | jq -r '.[].id'); do
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/assets/$asset_id
done
- name: Upload New Asset
if: ${{ steps.check-if-release-exists.outputs.release-exists == 1 }}
run: |
for asset_path in ./packages/rtc/dist/${{ env.RTC_PACKAGE_PATH }} ./packages/fake/rtc/dist/${{ env.RTC_FAKE_PACKAGE_PATH }}; do
asset_name=$(basename $asset_path)
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/zip" --data-binary @$asset_path "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=$asset_name"
done
- name: Prepare CDN Publish iris-web-rtc
if: ${{ inputs.cdn }}
run: |
GITHUB_RELEASE_DOWNLOAD_PREFIX=https://github.com/AgoraIO-Extensions/iris_web/releases/download
GITHUB_RELEASE_RTC_PACKAGE_DOWNLOAD_URL="${GITHUB_RELEASE_DOWNLOAD_PREFIX}/v${{ env.version }}/${{ env.RTC_PACKAGE_PATH }}"
echo "GITHUB_RELEASE_RTC_PACKAGE_DOWNLOAD_URL=${GITHUB_RELEASE_RTC_PACKAGE_DOWNLOAD_URL}" >> $GITHUB_ENV
- name: CDN Publish iris-web-rtc
if: ${{ inputs.cdn }}
env:
UPLOAD_CDN_INTERNAL_JENKINS_HOOK: ${{ secrets.UPLOAD_CDN_INTERNAL_JENKINS_HOOK }}
uses: AgoraIO-Extensions/actions/.github/actions/upload_cdn_internal@main
with:
upload_cdn_internal_jenkins_hook: ${{ env.UPLOAD_CDN_INTERNAL_JENKINS_HOOK }}
url: ${{ env.GITHUB_RELEASE_RTC_PACKAGE_DOWNLOAD_URL }}
release_type: 'sdk'
- name: Prepare CDN Publish iris-web-rtc
if: ${{ inputs.cdn }}
run: |
GITHUB_RELEASE_DOWNLOAD_PREFIX=https://github.com/AgoraIO-Extensions/iris_web/releases/download
GITHUB_RELEASE_RTC_FAKE_PACKAGE_DOWNLOAD_URL="${GITHUB_RELEASE_DOWNLOAD_PREFIX}/v${{ env.version }}/${{ env.RTC_FAKE_PACKAGE_PATH }}"
echo "GITHUB_RELEASE_RTC_FAKE_PACKAGE_DOWNLOAD_URL=${GITHUB_RELEASE_RTC_FAKE_PACKAGE_DOWNLOAD_URL}" >> $GITHUB_ENV
- name: CDN Publish iris-web-rtc-fake
if: ${{ inputs.cdn }}
env:
UPLOAD_CDN_INTERNAL_JENKINS_HOOK: ${{ secrets.UPLOAD_CDN_INTERNAL_JENKINS_HOOK }}
uses: AgoraIO-Extensions/actions/.github/actions/upload_cdn_internal@main
with:
upload_cdn_internal_jenkins_hook: ${{ env.UPLOAD_CDN_INTERNAL_JENKINS_HOOK }}
url: ${{ env.GITHUB_RELEASE_RTC_FAKE_PACKAGE_DOWNLOAD_URL }}
release_type: 'sdk'