Skip to content

Commit

Permalink
ci: refactor ci (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 authored Nov 16, 2024
1 parent c2401a5 commit 57a27a7
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 116 deletions.
34 changes: 21 additions & 13 deletions .github/actions/init-template-with-renderer/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: 'Init template with all dependencies renderer'
description: 'Install all necessary dependencies and init a renderer package'
name: Setup boilerplate
inputs:
renderer-template:
description: 'type of renderer package to init'
description: Define what vite template should be used to create renderer in case if renderer package doesn't exist
required: false
default: ''


runs:
using: "composite"
steps:
Expand All @@ -19,19 +19,21 @@ runs:
with:
node-version: 'latest'

- run: npm run create-renderer -- -- --template ${{inputs.renderer-template}}
shell: bash
if: inputs.renderer-template != ''

- run: npm start --workspace @vite-electron-builder/integrate-renderer
- name: Check if renderer directory exists
id: check-renderer
run: >-
if [ -d "packages/renderer" ]; then
echo "RENDERER_EXIST=true" >> $GITHUB_OUTPUT
else
echo "RENDERER_EXIST=false" >> $GITHUB_OUTPUT
fi
shell: bash
if: inputs.renderer-template != ''

- run: |
mkdir packages/renderer
echo "{\"name\":\"@vite-electron-builder/renderer\"}" > packages/renderer/package.json
npm run create-renderer -- -- --template ${{inputs.renderer-template}}
npm start --workspace @vite-electron-builder/integrate-renderer
shell: bash
if: inputs.renderer-template == ''
if: inputs.renderer-template != '' && steps.check-renderer.outputs.RENDERER_EXIST == 'false'
- name: Cache Dependencies
uses: actions/cache@v4
Expand All @@ -41,5 +43,11 @@ runs:
restore-keys: |
npm-${{ runner.os }}-${{ inputs.renderer-template }}-
- run: npm install
- name: Install Dependencies
run: >-
if [ "${{ steps.check-renderer.outputs.RENDERER_EXIST }}" == "true" ] && [ -f "package-lock.json" ]; then
npm ci
else
npm install
fi
shell: bash
71 changes: 71 additions & 0 deletions .github/workflows/boilerplate-ci-entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This file serves as a boilerplate template rather than an end-application script.
# The final application is likely to delete this file and use `ci.yml` as the entry point.

on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**.md'
- .editorconfig
- '.idea/**'
- '.vscode/**'
pull_request:
paths-ignore:
- '**.md'
- .editorconfig
- '.idea/**'
- '.vscode/**'

concurrency:
group: ${{github.workflow}}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
run-ci-for-template:
name: ci.yml
uses: ./.github/workflows/ci.yml
with:
renderer-template: ${{ matrix.renderer-template }}
distribution-channel: ${{ matrix.renderer-template }}
strategy:
fail-fast: false
matrix:
renderer-template:
- vanilla
- vanilla-ts
- vue
- vue-ts
- react
- react-ts
- react-swc
- react-swc-ts
- preact
- preact-ts
- lit
- lit-ts
- svelte
- svelte-ts
- solid
- solid-ts
# - qwik
# - qwik-ts

dependabot:
permissions:
contents: write
pull-requests: write
needs:
- run-ci-for-template
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'cawa-93/vite-electron-builder'
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
108 changes: 24 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,55 @@
# This workflow is the entry point for all CI processes.
# It is from here that all other workflows are launched.
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**.md'
- .editorconfig
- '.idea/**'
- '.vscode/**'
pull_request:
paths-ignore:
- '**.md'
- .editorconfig
- '.idea/**'
- '.vscode/**'
workflow_call:
inputs:
distribution-channel:
description: Distribution channel for release. It can be `beta`, `alpha` or any string.
type: string
required: true
renderer-template:
description: Define what vite template should be used to create renderer in case if renderer package doesn't exist
required: false
type: string
default: ''

concurrency:
group: ${{github.workflow}}-${{ github.ref }}
group: ${{github.workflow}}-${{ github.ref }}-${{inputs.distribution-channel}}
cancel-in-progress: true

permissions:
contents: write

jobs:
prepare:
name: Prepare shared data for multi-platform compilation
runs-on: ubuntu-latest
outputs:
APP_VERSION: ${{ steps.APP_VERSION.outputs.APP_VERSION }}
COMMIT_TIMESTAMP: ${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}
APP_FULL_VERSION: ${{ steps.APP_FULL_VERSION.outputs.APP_FULL_VERSION }}
steps:
- uses: actions/checkout@v4
- id: COMMIT_TIMESTAMP
run: echo "COMMIT_TIMESTAMP=$(git show -s --format=%ct ${{ github.sha }})" >> $GITHUB_OUTPUT
- id: APP_VERSION
run: echo "APP_VERSION=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- id: APP_FULL_VERSION
run: echo "APP_FULL_VERSION=${{ steps.APP_VERSION.outputs.APP_VERSION }}-${{inputs.distribution-channel}}.${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}" >> $GITHUB_OUTPUT
- run: |
echo "- \`COMMIT_TIMESTAMP\`: ${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}" >> $GITHUB_STEP_SUMMARY
echo "- \`APP_VERSION\`: ${{ steps.APP_VERSION.outputs.APP_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- \`APP_FULL_VERSION\`: ${{ steps.APP_FULL_VERSION.outputs.APP_FULL_VERSION }}" >> $GITHUB_STEP_SUMMARY
compile-and-test:
needs:
- prepare
uses: ./.github/workflows/compile-and-test.yml
with:
renderer-template: ${{ matrix.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_VERSION }}
build-number: ${{ needs.prepare.outputs.COMMIT_TIMESTAMP }}
strategy:
fail-fast: false
matrix:
renderer-template:
- vanilla
- vanilla-ts
- vue
- vue-ts
- react
- react-ts
- react-swc
- react-swc-ts
- preact
- preact-ts
- lit
- lit-ts
- svelte
- svelte-ts
- solid
- solid-ts
# Qwik Has unresolved upstream issue. So I decided to torn it off for now
# - qwik
# - qwik-ts
renderer-template: ${{ inputs.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_FULL_VERSION }}
distribution-channel: ${{inputs.distribution-channel}}

deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
Expand All @@ -79,45 +59,5 @@ jobs:
- compile-and-test
uses: ./.github/workflows/deploy.yml
with:
renderer-template: ${{ matrix.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_VERSION }}
build-number: ${{ needs.prepare.outputs.COMMIT_TIMESTAMP }}
strategy:
fail-fast: false
matrix:
renderer-template:
- vanilla
- vanilla-ts
- vue
- vue-ts
- react
- react-ts
- react-swc
- react-swc-ts
- preact
- preact-ts
- lit
- lit-ts
- svelte
- svelte-ts
- solid
- solid-ts
# Qwik Has unresolved upstream issue. So I decided to torn it off for now
# - qwik
# - qwik-ts


dependabot:
permissions:
contents: write
pull-requests: write
needs:
- compile-and-test
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'cawa-93/vite-electron-builder'
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
distribution-channel: ${{ inputs.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_FULL_VERSION }}
17 changes: 9 additions & 8 deletions .github/workflows/compile-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ on:
workflow_call:
inputs:
renderer-template:
required: true
description: Define what vite template should be used to create renderer in case if renderer package doesn't exist
required: false
type: string
default: ''
app-version:
required: true
type: string
build-number:
distribution-channel:
required: true
type: string

Expand All @@ -29,7 +31,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/init-template-with-renderer
name: Init template with "${{inputs.renderer-template}}" renderer
name: Setup boilerplate
with:
renderer-template: ${{inputs.renderer-template}}
- run: npm run typecheck --if-present
Expand All @@ -46,20 +48,19 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/init-template-with-renderer
name: Init template with "${{inputs.renderer-template}}" renderer
name: Setup boilerplate
with:
renderer-template: ${{inputs.renderer-template}}

- run: npm version "${{inputs.app-version}}-${{inputs.renderer-template}}.${{inputs.build-number}}" --no-git-tag-version
- run: npm version "${{inputs.app-version}}" --no-git-tag-version
- run: npm run compile -- -p never
env:
VITE_DISTRIBUTION_CHANNEL: ${{inputs.renderer-template}}
BUILD_NUMBER: ${{inputs.build-number}}
VITE_DISTRIBUTION_CHANNEL: ${{inputs.distribution-channel}}

- run: npm run test --if-present

- name: Upload compiled app
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{inputs.renderer-template}}
name: ${{ matrix.os }}-${{inputs.distribution-channel}}
path: dist
16 changes: 5 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ name: Deploy
on:
workflow_call:
inputs:
renderer-template:
required: true
type: string
app-version:
required: true
type: string
build-number:
distribution-channel:
required: true
type: string

Expand All @@ -26,22 +23,19 @@ env:
npm_config_audit: false
npm_config_fund: false


jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: ${{inputs.renderer-template}}
url: https://github.com/${{github.repository}}/releases/tag/v${{inputs.app-version}}-${{inputs.renderer-template}}.${{inputs.build-number}}
name: ${{inputs.distribution-channel}}
url: https://github.com/${{github.repository}}/releases/tag/v${{inputs.app-version}}
steps:
- name: Set pattern variable
run: echo "pattern=*-${{inputs.renderer-template}}" >> $GITHUB_ENV
- name: Download compiled app
uses: actions/download-artifact@v4
with:
pattern: "*-${{inputs.renderer-template}}"
pattern: "*-${{inputs.distribution-channel}}"
path: dist
merge-multiple: true
- run: gh release create v${{inputs.app-version}}-${{inputs.renderer-template}}.${{inputs.build-number}} dist/*${{inputs.renderer-template}}* dist/latest*.yml --repo ${{github.repository}}
- run: gh release create v${{inputs.app-version}} dist/root* dist/latest*.yml --repo ${{github.repository}}
env:
GH_TOKEN: ${{ github.token }}
5 changes: 5 additions & 0 deletions electron-builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export default /** @type import('electron-builder').Configuration */
linux: {
target: ['deb'],
},
/**
* It is recommended to avoid using non-standard characters such as spaces in artifact names,
* as they can unpredictably change during deployment, making them impossible to locate and download for update.
*/
artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
files: [
'packages/entry-point.js',
'!node_modules/@vite-electron-builder/**',
Expand Down

0 comments on commit 57a27a7

Please sign in to comment.