Skip to content

Publish

Publish #94

Workflow file for this run

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'