Release New Version #137
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release New Version | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseType: | |
description: 'Release' | |
required: false | |
default: '' | |
preReleaseFlavor: | |
description: 'Pre-Release flavor - rc, beta, or anything' | |
required: false | |
default: '' | |
jobs: | |
create-release-draft: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Tag | |
id: prep | |
run: | | |
TAG_NAME=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name | select (. != null)") | |
IS_DRAFT=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .draft | select (. != null)") | |
if [ -n "${TAG_NAME}" ] && [ "${IS_DRAFT}" == "false" ];then | |
echo "A release has already been published for this run_id (${{ github.run_id }} / ${TAG_NAME})." | |
exit 1 | |
fi | |
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
with: | |
ref: ${{ github.ref }} | |
fetch-depth: 0 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Setup Git | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
run: | | |
git config --global user.name "devx-sauce-bot" | |
git config --global user.email "devx.bot@saucelabs.com" | |
- name: Install Dependencies | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
run: npm ci | |
- name: Build Bundle | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
run: npm run build | |
- name: Generate (Pre-)Release Draft | |
if: ${{ steps.prep.outputs.tag_name == '' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
if [ -z "${{ github.event.inputs.releaseType }}" ] && [ -z "${{ github.event.inputs.preReleaseFlavor }}" ];then | |
echo "No release type provided." | |
exit 1 | |
fi | |
if [ -n "${{ github.event.inputs.preReleaseFlavor }}" ];then | |
PRE_RELEASE_ARGS="--preRelease=${{ github.event.inputs.preReleaseFlavor }} --github.preRelease" | |
fi | |
npx release-it ${{ github.event.inputs.releaseType }} ${PRE_RELEASE_ARGS} | |
release-windows-bundle: | |
runs-on: windows-latest | |
needs: [create-release-draft] | |
steps: | |
- name: Find matching draft tag | |
id: prep | |
run: | | |
$res = Invoke-WebRequest -Uri "https://api.github.com/repos/${{ github.repository }}/releases" -Headers @{'Authorization' = "token ${{ github.token }}"} | |
$jsonObj = ConvertFrom-Json $([String]::new($res.Content)) | |
$selectedRelease = $null | |
Foreach ($release in $jsonObj) | |
{ | |
if ( ! $release.body -contains "- jobId: ${{ github.run_id }}\\n") { | |
continue | |
} | |
if ( ! $release.draft ) { | |
continue | |
} | |
$selectedRelease = $release | |
break | |
} | |
if ( $null -eq $selectedRelease ) { | |
exit 1 | |
} | |
$selectedAsset = $null | |
Foreach ($asset in $selectedRelease.assets) { | |
if ($asset.name -eq "testcafe-windows-amd64.zip") { | |
$selectedAsset = $asset | |
} | |
} | |
$tagName = $selectedRelease.tag_name | |
$releaseId = $selectedRelease.id | |
$assetId = $selectedAsset.id | |
echo "version=$tagName" >> $Env:GITHUB_OUTPUT | |
echo "release_id=$releaseId" >> $Env:GITHUB_OUTPUT | |
echo "asset_id=$assetId" >> $Env:GITHUB_OUTPUT | |
- run: Write-Output "${{ steps.prep.outputs.release_id }} - ${{ steps.prep.outputs.version }} - ${{ steps.prep.outputs.asset_id }}" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
with: | |
ref: ${{ steps.prep.outputs.version }} | |
- name: Setup Node | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Update Release Version | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: | | |
npm version --no-git-tag-version ${{ steps.prep.outputs.version }} | |
- name: Install Dependencies | |
run: npm ci --production | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
- name: Bundle Directory | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: bash ./scripts/bundle.sh | |
- name: List Bundle Contents | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: ls -R bundle/ | |
- name: Archive Bundle | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
uses: azure/powershell@v1 | |
with: | |
inlineScript: | | |
Compress-Archive bundle/ testcafe-windows-amd64.zip | |
azPSVersion: '3.1.0' | |
- name: Upload Release Asset | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
gh release upload ${{ steps.prep.outputs.version }} testcafe-windows-amd64.zip | |
release-macos-bundle: | |
runs-on: macos-latest | |
needs: [create-release-draft] | |
steps: | |
- name: Find matching draft tag | |
id: prep | |
run: | | |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name") | |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .id") | |
if [ "${VERSION}" = "" ];then | |
echo "No draft version found" | |
exit 1 | |
fi | |
ASSET_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .assets | .[] | select(.name == \"testcafe-macos-amd64.zip\") | .id | select(. != null)") | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT | |
echo "asset_id=${ASSET_ID}" >> $GITHUB_OUTPUT | |
- run: echo "${{ steps.prep.outputs.release_id }} - ${{ steps.prep.outputs.version }} - ${{ steps.prep.outputs.asset_id }}" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
with: | |
ref: ${{ steps.prep.outputs.version }} | |
- name: Setup Node | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Update Release version | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: | | |
npm version --no-git-tag-version ${{ steps.prep.outputs.version }} | |
- name: Install Dependencies | |
run: npm ci --production | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
- name: Setup ffmpeg | |
uses: FedericoCarboni/setup-ffmpeg@v2 | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
id: setup-ffmpeg | |
with: | |
token: ${{ github.token }} | |
- name: Bundle Directory | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: bash ./scripts/bundle.sh | |
- name: List Bundle Contents | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: ls -R bundle/ | |
- name: Archive Bundle | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
run: zip -r testcafe-macos-amd64.zip bundle/ | |
- name: Upload Release Asset | |
if: ${{ steps.prep.outputs.asset_id == '' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
gh release upload ${{ steps.prep.outputs.version }} testcafe-macos-amd64.zip | |
publish-release: | |
runs-on: ubuntu-latest | |
needs: [release-windows-bundle, release-macos-bundle] | |
steps: | |
- name: Find Matching Draft Tag | |
id: prep | |
run: | | |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .id") | |
if [ "${RELEASE_ID}" = "" ];then | |
echo "No draft version found" | |
exit 1 | |
fi | |
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT | |
- name: Publish Release | |
run: | | |
curl -f -X PATCH -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.prep.outputs.release_id }} \ | |
-d '{"draft":"false"}' | |
# Post Deploy Tests | |
post-release-windows-tests: | |
runs-on: ubuntu-latest | |
needs: publish-release | |
env: | |
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}} | |
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup saucectl | |
uses: saucelabs/saucectl-run-action@v4 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
skip-run: true | |
- name: Parse Release Version | |
id: parse_version | |
run: | | |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name") | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
- name: Cloud Tests (Windows) | |
working-directory: ./tests/post-release | |
env: | |
BUILD_ID: Github RUN ID ${{ env.GITHUB_RUN_ID }} | |
run: | | |
saucectl run --config ./.sauce/config_win.yml --runner-version "url: https://github.com/saucelabs/sauce-testcafe-runner/releases/download/${{ steps.parse_version.outputs.version }}/testcafe-windows-amd64.zip" | |
post-release-macos-tests: | |
runs-on: ubuntu-latest | |
needs: publish-release | |
env: | |
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}} | |
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup saucectl | |
uses: saucelabs/saucectl-run-action@v4 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
skip-run: true | |
- name: Parse Release Version | |
id: parse_version | |
run: | | |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | \ | |
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name") | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
- name: Cloud Tests (MacOS) | |
working-directory: ./tests/post-release | |
env: | |
BUILD_ID: Github RUN ID ${{ env.GITHUB_RUN_ID }} | |
run: | | |
saucectl run --config ./.sauce/config_mac.yml --runner-version "url: https://github.com/saucelabs/sauce-testcafe-runner/releases/download/${{ steps.parse_version.outputs.version }}/testcafe-macos-amd64.zip" |