3.7.4 #147
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 Version | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- closed | |
- synchronize | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
prepare-release-assets: | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.draft_release.outputs.upload_url }} | |
release_id: ${{ steps.draft_release.outputs.release_id }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '21' | |
- name: Install dependencies | |
run: cd src && yarn | |
- name: Extract tag name | |
id: extract_tag | |
run: | | |
echo "VERSION=${{ github.event.pull_request.title }}" >> $GITHUB_ENV | |
echo GOOGLE_ANALYTICS_API_SECRET=${{ secrets.GOOGLE_ANALYTICS_API_SECRET }} >> .env | |
- name: Build and zip the extension | |
run: | | |
mkdir dist | |
cd src | |
yarn run build-css | |
yarn run dist | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
VERSION: ${{ env.VERSION }} | |
SENTRY_RELEASE: "shortcut-assistant@${{ env.VERSION }}" | |
- name: Upload dist.zip as an artifact | |
uses: actions/[email protected] | |
with: | |
name: dist-zip | |
path: dist/dist.zip | |
- name: Create or update draft release | |
id: draft_release | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const { owner, repo } = context.repo; | |
const pr = context.payload.pull_request; | |
const releaseTag = pr.title; | |
const releaseNotes = pr.body; | |
const releases = await github.rest.repos.listReleases({ | |
owner, | |
repo, | |
}); | |
let draftRelease = releases.data.find(release => release.tag_name === releaseTag && release.draft === true); | |
if (!draftRelease) { | |
console.log(`Creating draft release`); | |
draftRelease = await github.rest.repos.createRelease({ | |
owner, | |
repo, | |
tag_name: releaseTag, | |
name: releaseTag, | |
body: releaseNotes, | |
draft: true, | |
}); | |
console.log(`Draft release created`); | |
} | |
console.log(draftRelease) | |
core.setOutput("upload_url", draftRelease.upload_url); | |
core.setOutput("release_id", draftRelease.id); | |
upload-release-asset: | |
needs: prepare-release-assets | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
steps: | |
- name: Download dist.zip artifact | |
uses: actions/[email protected] | |
with: | |
name: dist-zip | |
path: dist | |
- name: Upload release asset | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const { owner, repo } = context.repo; | |
const pr = context.payload.pull_request; | |
const releases = await github.rest.repos.listReleases({ | |
owner, | |
repo, | |
}); | |
const releaseTag = pr.title; | |
let draftRelease = releases.data.find(release => release.tag_name === releaseTag && release.draft === true); | |
const releaseId = draftRelease.id; | |
const assetPath = './dist/dist.zip'; | |
const assetName = 'ChromeExtension.zip'; | |
const assetContentType = 'application/zip'; | |
const data = require('fs').readFileSync(assetPath); | |
console.log(`Uploading asset ${assetPath} to release ${releaseId}`); | |
console.log(`Release published: https://github.com/${owner}/${repo}/releases/tag/${releaseId}`); | |
release = await github.rest.repos.updateRelease({ | |
owner, | |
repo, | |
release_id: releaseId, | |
draft: false, | |
}); | |
await github.rest.repos.uploadReleaseAsset({ | |
owner, | |
repo, | |
release_id: releaseId, | |
name: assetName, | |
data, | |
}); | |
console.log('Asset uploaded'); |