Skip to content

Commit

Permalink
ci: Тепер публікація оновлень здійснюється створенням нового випуску …
Browse files Browse the repository at this point in the history
…в GitHub
  • Loading branch information
cawa-93 committed Jul 27, 2023
1 parent 24d7e25 commit 4678994
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 38 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@

name: Deploy

on: [ workflow_dispatch ]
on:
workflow_dispatch:
inputs:
VERSION_REF:
required: true
type: string
description: Set app version to deploy in semver format [0-9].[0-9].[0-9]
release:
types: [ created ]

jobs:

test:
uses: ./.github/workflows/test.yml
with:
VERSION_REF: ${{ inputs.VERSION_REF || github.ref }}


deploy-chrome:
deploy:
needs: [ test ]

runs-on: ubuntu-latest
Expand All @@ -30,8 +40,12 @@ jobs:
- run: pnpm install
- run: pnpm run build
env:
VERSION_REF: ${{ inputs.VERSION_REF || github.ref }}
BUILD_TARGET: chrome

- run: cat dist/manifest.json
- run: echo ${{ github.ref }}

- run: pnpm run web-ext:pack

- name: Browser Platform Publish
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
name: Run tests

on: [ push, pull_request, workflow_dispatch, workflow_call ]
on:
push:
pull_request:
workflow_call:
inputs:
VERSION_REF:
required: true
type: string
description: Set app version to deploy in semver format [0-9].[0-9].[0-9]
workflow_dispatch:
inputs:
VERSION_REF:
required: false
default: 0.0.0
type: string
description: Set app version to deploy in semver format [0-9].[0-9].[0-9]

jobs:
test:
Expand All @@ -18,14 +33,17 @@ jobs:
node-version: 18

- run: pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
# - name: Install Playwright Browsers
# run: pnpm exec playwright install --with-deps

- run: pnpm run build
env:
VERSION_REF:
${{ inputs.VERSION_REF || ( github.ref_type == 'tag' && github.ref || '0.0.0') }}
BUILD_TARGET: chrome

- run: pnpm run test

- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"private": true,
"version": "0.0.2",
"type": "module",
"scripts": {
"dev": "vite build --watch --minify false --mode chrome",
Expand Down
97 changes: 65 additions & 32 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,84 @@ import vue from '@vitejs/plugin-vue'
import {viteVueCESubStyle} from '@unplugin-vue-ce/sub-style'
import chromeI18nBlock from 'vite-plugin-vue-chrome-i18n'

/**
* @param {'chrome' | 'edge' | 'firefox'} target
* @returns {chrome.runtime.Manifest}
*/
function getManifest(target) {

const chromeBackground = {
service_worker: "src/background/index.ts",
}

const firefoxBackground = {
scripts: [
'src/background/index.ts'
]
export default defineConfig(({mode,}) => {

/**
*
* @type {{
* VERSION_REF: string | undefined,
* npm_package_version: string | undefined,
* BUILD_TARGET: 'chrome' | 'edge' | 'firefox' | undefined
* }}
*/
const ENV = loadEnv(mode, process.cwd(), '')

const supportedBuildTarget = ['chrome', 'edge', 'firefox']

if (!supportedBuildTarget.includes(ENV.BUILD_TARGET)) {
throw new Error(`The BUILD_TARGET environment variable is not specified correctly. Valid values are: ${supportedBuildTarget} You have submitted: ${JSON.stringify(ENV.BUILD_TARGET)}`)
}

return {
name: '__MSG_APP_NAME__',
description: '__MSG_APP_DESCRIPTION__',
version: process.env.npm_package_version,
manifest_version: 3,
default_locale: 'en',
icons: {
"128": "icons/128.png"
},

function resolveAppVersion() {
const {VERSION_REF, npm_package_version} = ENV

action: {},

permissions: ["activeTab", "scripting"],
let resolvedVersion = ''

background: target === 'firefox' ? firefoxBackground : chromeBackground,
if (VERSION_REF) {
const versionFromRef = VERSION_REF.match(/^(?:refs\/tags\/)?v?([0-9]+\.[0-9]+\.[0-9]+)$/)?.[1]
if (versionFromRef) {
resolvedVersion = versionFromRef
} else {
throw new Error(`Can not resolve version from VERSION_REF. VERSION_REF is ${JSON.stringify(VERSION_REF)} and resolvedVersion is ${resolvedVersion}`)
}
} else if (npm_package_version) {
resolvedVersion = npm_package_version;
}

if (!resolvedVersion) {
throw new Error('Unable to resolve version. You must specify the VERSION_REF environment variable with the semver version or git reference to tag with version or specify the version in the package.json.')
}

return resolvedVersion;
}
}

export default defineConfig(({mode,}) => {
/**
* @returns {chrome.runtime.Manifest}
*/
function getManifest() {

const chromeBackground = {
service_worker: "src/background/index.ts",
}

const {BUILD_TARGET, npm_package_version} = loadEnv(mode, process.cwd(), '')
const supportedBuildTarget = ['chrome', 'edge', 'firefox']
const firefoxBackground = {
scripts: [
'src/background/index.ts'
]
}

const version = resolveAppVersion()

if (!supportedBuildTarget.includes(BUILD_TARGET)) {
throw new Error(`The BUILD_TARGET environment variable is not specified correctly. Valid values are: ${supportedBuildTarget} You have submitted: ${JSON.stringify(BUILD_TARGET)}`)
return {
manifest_version: 3,
name: '__MSG_APP_NAME__',
description: '__MSG_APP_DESCRIPTION__',
version,
default_locale: 'en',
icons: {
"128": "icons/128.png"
},
action: {},
permissions: ["activeTab", "scripting"],
background:
ENV.BUILD_TARGET === 'firefox' ? firefoxBackground : chromeBackground,
}
}


return {
plugins: [
vue({
Expand Down Expand Up @@ -79,7 +112,7 @@ export default defineConfig(({mode,}) => {
}),
viteVueCESubStyle(),
webExtension({
manifest: getManifest(BUILD_TARGET),
manifest: getManifest(),
additionalInputs: {
scripts: ['src/content/main.ts']
}
Expand Down

0 comments on commit 4678994

Please sign in to comment.