Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): add nightly builds, rename zips #509

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/actions/get-built-version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires */
const path = require('node:path')
const fs = require('node:fs/promises')

/**
* Retrieves the manifest version from the built extension.
* @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments
*/
module.exports = async ({ core }) => {
const manifestPath = path.join(__dirname, 'dist', 'chrome', 'manifest.json')
const manifest = await fs.readFile(manifestPath, 'utf8').then(JSON.parse)

core.setOutput('version', manifest.version)
}
1 change: 1 addition & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Environment setup
description: Sets up Node and pnpm

runs:
using: 'composite'
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Nightly build

on:
schedule:
- cron: '0 0 * * 1-6'
workflow_dispatch:
inputs: {}

permissions:
contents: write

defaults:
run:
shell: bash

jobs:
build-nightly:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Environment setup
uses: ./.github/actions/setup

- name: Build
run: pnpm build --channel=nightly

- name: Get built version
uses: actions/github-script@v7
id: version
with:
script: |
const script = require('./.github/actions/get-built-version.cjs')
await script({ github, context, core })

- name: Delete existing release
run: gh release delete nightly --cleanup-tag --yes
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}

- name: Create GH Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/*.zip
tag_name: 'nightly'
name: Nightly ${{ steps.version.outputs.version }}
prerelease: true
1 change: 1 addition & 0 deletions cspell-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data-testid
nums

# scripts and 3rd party terms
nvmrc
typecheck
prettiercache
corepack
Expand Down
28 changes: 23 additions & 5 deletions esbuild/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWriteStream } from 'node:fs'
import path from 'node:path'
import type { BuildOptions, Plugin as ESBuildPlugin } from 'esbuild'
import archiver from 'archiver'
import type { BuildArgs } from './config'
import type { BuildArgs, Channel, Target, WebExtensionManifest } from './config'
import { getPlugins } from './plugins'
import { typecheckPlugin } from '@jgoz/esbuild-plugin-typecheck'

Expand All @@ -22,7 +22,7 @@ export const getProdOptions = ({
plugins: getPlugins({ outDir, dev: false, target, channel }).concat([
typecheckPlugin({ buildMode: 'readonly' }),
preservePolyfillClassNamesPlugin({ outDir }),
zipPlugin({ outDir })
zipPlugin({ outDir, target, channel })
]),
define: {
NODE_ENV: JSON.stringify('production'),
Expand All @@ -36,16 +36,34 @@ export const getProdOptions = ({
}
}

function zipPlugin({ outDir }: { outDir: string }): ESBuildPlugin {
function zipPlugin({
outDir,
target,
channel
}: {
channel: Channel
target: Target
outDir: string
}): ESBuildPlugin {
return {
name: 'zip',
setup(build) {
build.onEnd(async () => {
const output = createWriteStream(`${outDir}.zip`)
const manifest = JSON.parse(
await fs.readFile(path.join(outDir, 'manifest.json'), 'utf8')
) as WebExtensionManifest

let zipName = `${target}-${manifest.version}.zip`
if (channel !== 'stable') {
zipName = `${channel}-${zipName}`
}

const dest = path.join(outDir, '..', zipName)
const output = createWriteStream(dest)
const archive = archiver('zip')
archive.on('end', function () {
const archiveSize = archive.pointer()
const fileName = path.relative(process.cwd(), `${outDir}.zip`)
const fileName = path.relative(process.cwd(), dest)
console.log(` Archived ${fileName}: ${formatBytes(archiveSize)}`)
})
archive.pipe(output)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/archiver": "^6.0.2",
"@types/github-script": "github:actions/github-script",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
Expand Down
Loading