Skip to content

Commit

Permalink
feat(ci): add nightly builds
Browse files Browse the repository at this point in the history
Update build script to generate correct zip names

Co-authored-by: Radu-Cristian Popa <[email protected]>
  • Loading branch information
sidvishnoi and raducristianpopa committed Aug 20, 2024
1 parent 701a062 commit 3f218d3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
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
46 changes: 46 additions & 0 deletions .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
id: build
run: |
pnpm build
echo "VERSION=$(jq -r '.version' './dist/chrome/manifest.json')" >> $GITHUB_OUTPUT
- 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.build.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
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/chrome-manifest",
"name": "__MSG_appName__",
"version": "0.1.1",
"version": "0.1.1.0",
"manifest_version": 3,
"minimum_chrome_version": "110.0",
"description": "__MSG_appDescription__",
Expand Down

0 comments on commit 3f218d3

Please sign in to comment.