Skip to content

Commit

Permalink
build: do CFA releases (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Feb 20, 2023
1 parent d974b04 commit 56668ce
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 46 deletions.
67 changes: 66 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ commands:
keys:
- v1-dependencies-{{ arch }}-{{ checksum "package-lock.json" }}
- v1-dependencies-{{ arch }}
- run: npm install
- when:
condition: << pipeline.git.tag >>
steps:
- run:
name: Update Version
command: node script/update-version.js << pipeline.git.tag >>
- run: npm install
- unless:
condition: << pipeline.git.tag >>
steps:
- run:
command: npm install
environment:
ELECTRON_CHROMEDRIVER_STABLE_FALLBACK: 1
- save_cache:
paths:
- node_modules
Expand Down Expand Up @@ -65,6 +78,32 @@ jobs:
- install:
node-version: << parameters.node-version >>
- test
release:
docker:
- image: cimg/node:18.14
steps:
- checkout
- run:
name: Update Version
command: node script/update-version.js << pipeline.git.tag >>
- run:
name: Install Dependencies
command: npm ci
- run:
name: Obtain Publishing Credentials
command: npx @continuous-auth/[email protected]
- run:
name: Confirm Version Updated
command: node -e "if (require('./package.json').version === '0.0.0-development') process.exit(1)"
- run:
name: Set NPM Credentials
command: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > ~/.npmrc
- run:
name: Check NPM Credentials
command: npm whoami
- run:
name: CFA Publish
command: node script/publish.js

workflows:
test_and_release:
Expand All @@ -76,17 +115,43 @@ workflows:
- 18.14.0
- 16.19.0
- 14.19.0
filters:
tags:
only: /.*/
- test-mac:
matrix:
parameters:
node-version:
- 18.14.0
- 16.19.0
- 14.19.0
filters:
tags:
only: /.*/
- test-windows:
matrix:
parameters:
node-version:
- 18.14.0
- 16.19.0
- 14.19.0
filters:
tags:
only: /.*/
- release:
requires:
- test-linux-18.14.0
- test-linux-16.19.0
- test-linux-14.19.0
- test-mac-18.14.0
- test-mac-16.19.0
- test-mac-14.19.0
- test-windows-18.14.0
- test-windows-16.19.0
- test-windows-14.19.0
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
context: cfa-release
38 changes: 8 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
run_tests:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
smoke_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # tag: v3.3.0
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # tag: v3.6.0
with:
node-version: "16.19.0"
- name: Update Version
run: node script/update-version.js ${{ github.event.inputs.version }}
- name: Install Dependencies
Expand All @@ -26,37 +27,14 @@ jobs:
run: npm test
create_new_version:
runs-on: ubuntu-latest
needs: run_tests
needs: smoke_test
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # tag: v3.3.0
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # tag: v3.6.0
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
- name: Check npm credentials
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Set Git Credentials
run: |
git config user.name electron-bot
git config user.email [email protected]
- name: Update Version
run: node script/update-version.js ${{ github.event.inputs.version }}
- name: Push Update Commit
run: |
git add .
git commit -m "chore: update version to ${{ github.event.inputs.version }}"
git push origin main
# Tag here, the CircleCI workflow will trigger on the new tag and do the CFA publish
- name: Push New Tag
run: |
git tag ${{ github.event.inputs.version }}
git push origin ${{ github.event.inputs.version }}
- name: Create Release
run: |
gh release create ${{ github.event.inputs.version }} -t ${{ github.event.inputs.version }}
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
39 changes: 39 additions & 0 deletions download-chromedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ const { downloadArtifact } = require('@electron/get')
const extractZip = require('extract-zip')
const versionToDownload = require('./package').version

// Refs https://github.com/electron/fiddle-core/blob/1ee2d2737f23fd1012917a249a9444b6db89f1d8/src/versions.ts#L47-L57
function compareVersions (a, b) {
const l = a.compareMain(b)
if (l) return l
// Electron's approach is nightly -> other prerelease tags -> stable,
// so force `nightly` to sort before other prerelease tags.
const [prea] = a.prerelease
const [preb] = b.prerelease
if (prea === 'nightly' && preb !== 'nightly') return -1
if (prea !== 'nightly' && preb === 'nightly') return 1
return a.comparePre(b)
}

// Refs https://github.com/electron/fiddle-core/blob/1ee2d2737f23fd1012917a249a9444b6db89f1d8/src/versions.ts#L152-L160
function getLatestStable (releases) {
const { parse: semverParse } = require('semver')
const semvers = releases.map(({ version }) => semverParse(version)).filter((sem) => Boolean(sem))
semvers.sort((a, b) => compareVersions(a, b))
let stable
for (const ver of semvers.values()) {
if (ver.prerelease.length === 0) {
stable = ver
}
}
return stable
}

function download (version) {
return downloadArtifact({
version,
Expand All @@ -18,6 +45,18 @@ function download (version) {
}

async function attemptDownload (version) {
// Fall back to latest stable if there is not a stamped version, for tests
if (version === '0.0.0-development') {
if (!process.env.ELECTRON_CHROMEDRIVER_STABLE_FALLBACK) {
console.log('WARNING: chromedriver in development needs the environment variable ELECTRON_CHROMEDRIVER_STABLE_FALLBACK set')
process.exit(1)
}

const fetch = require('node-fetch')
const releases = await fetch('https://releases.electronjs.org/releases.json').then(response => response.json())
version = getLatestStable(releases).version
}

try {
const targetFolder = path.join(__dirname, 'bin')
const zipPath = await download(version)
Expand Down
Loading

0 comments on commit 56668ce

Please sign in to comment.