Skip to content

Commit

Permalink
ci: compile and deploy (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 authored Nov 12, 2024
2 parents 01951ff + 17dbaa9 commit 66b2102
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 17 deletions.
11 changes: 10 additions & 1 deletion .github/actions/init-template-with-renderer/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ description: 'Install all necessary dependencies and init a renderer package'
inputs:
renderer-template:
description: 'type of renderer package to init'
required: true
required: false
default: ''

runs:
using: "composite"
Expand All @@ -20,9 +21,17 @@ runs:

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

- run: npm start --workspace @vite-electron-builder/integrate-renderer
shell: bash
if: inputs.renderer-template != ''

- run: |
mkdir packages/renderer
echo "{\"name\":\"@vite-electron-builder/renderer\"}" > packages/renderer/package.json
shell: bash
if: inputs.renderer-template == ''
- name: Cache Dependencies
uses: actions/cache@v4
Expand Down
51 changes: 41 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,59 @@ jobs:
prepare:
runs-on: ubuntu-latest
outputs:
COMMIT_TIMESTAMP: ${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}
APP_CHANNEL: ${{ steps.APP_CHANNEL.outputs.APP_CHANNEL }}
APP_VERSION: ${{ steps.APP_VERSION.outputs.APP_VERSION }}
COMMIT_TIMESTAMP: ${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}
steps:
- uses: actions/checkout@v4
- id: COMMIT_TIMESTAMP
run: echo "COMMIT_TIMESTAMP=$(git show -s --format=%ct ${{ github.sha }})" >> $GITHUB_OUTPUT
- id: APP_CHANNEL
run: echo "APP_CHANNEL=$(if [[ "${{ github.ref }}" == 'refs/heads/develop' ]]; then echo 'beta'; else echo 'latest'; fi)" >> $GITHUB_OUTPUT
- id: APP_VERSION
run: echo "APP_VERSION=3.0.${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}$(if [[ "${{ steps.APP_CHANNEL.outputs.APP_CHANNEL }}" != 'latest' ]]; then echo '-${{ steps.APP_CHANNEL.outputs.APP_CHANNEL }}'; else echo ''; fi)" >> $GITHUB_OUTPUT
run: echo "APP_VERSION=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- run: |
echo "- \`COMMIT_TIMESTAMP\`: ${{ steps.COMMIT_TIMESTAMP.outputs.COMMIT_TIMESTAMP }}" >> $GITHUB_STEP_SUMMARY
echo "- \`APP_CHANNEL\`: ${{ steps.APP_CHANNEL.outputs.APP_CHANNEL }}" >> $GITHUB_STEP_SUMMARY
echo "- \`APP_VERSION\`: ${{ steps.APP_VERSION.outputs.APP_VERSION }}" >> $GITHUB_STEP_SUMMARY
tests:
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
deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- prepare
uses: ./.github/workflows/tests.yml
- compile-and-test
uses: ./.github/workflows/deploy.yml
with:
renderer-template: ${{ matrix.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_VERSION }}-${{ matrix.renderer-template }}
app-version: ${{ needs.prepare.outputs.APP_FULL_VERSION }}
build-number: ${{ needs.prepare.outputs.COMMIT_TIMESTAMP }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -85,7 +116,7 @@ jobs:
contents: write
pull-requests: write
needs:
- tests
- compile-and-test
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'cawa-93/vite-electron-builder'
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Compile and test

on:
workflow_call:
inputs:
Expand All @@ -7,6 +9,9 @@ on:
app-version:
required: true
type: string
build-number:
required: true
type: string

defaults:
run:
Expand All @@ -29,9 +34,9 @@ jobs:
renderer-template: ${{inputs.renderer-template}}
- run: npm run typecheck --if-present

tests:
compile:
strategy:
fail-fast: false
fail-fast: true
matrix:
os:
- windows-latest
Expand All @@ -44,6 +49,16 @@ jobs:
name: Init template with "${{inputs.renderer-template}}" renderer
with:
renderer-template: ${{inputs.renderer-template}}
- run: npm run compile -- --publish 'never' -c.extraMetadata.version=${{inputs.app-version}}
- run: rm -rf packages

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

- run: npm run test --if-present

- name: Upload compiled app
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{inputs.renderer-template}}
path: dist
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy

on:
workflow_call:
inputs:
renderer-template:
required: true
type: string
app-version:
required: true
type: string
build-number:
required: true
type: string

defaults:
run:
shell: 'bash'

env:
NODE_NO_WARNINGS: 1
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
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}}
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}}"
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 --draft --repo ${{github.repository}}
env:
GH_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .idea/jsonSchemas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"description": "Secure boilerplate for Electron app based on Vite",
"version": "2.0.0",
"version": "3.1.0",
"private": true,
"type": "module",
"author": {
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/modules/AutoUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class AutoUpdater implements AppModule {
updater.logger = this.#logger || null;
updater.fullChangelog = true;

if (import.meta.env.VITE_DISTRIBUTION_CHANNEL) {
updater.channel = import.meta.env.VITE_DISTRIBUTION_CHANNEL;
}

return await updater.checkForUpdatesAndNotify(this.#notification);
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit 66b2102

Please sign in to comment.