From 22d647f0cb0593eb10bc6c695c29b83e0e18fc96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20J=C3=B8rgensen?= Date: Thu, 8 Aug 2024 20:30:04 +0200 Subject: [PATCH] Ensure correct build output and upload artifacts --- .github/workflows/main.yml | 88 ++++++++---------------------- package.json | 109 ++++--------------------------------- rollup.config.mjs | 82 ++++------------------------ 3 files changed, 45 insertions(+), 234 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f12834d..81c9b00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,78 +1,34 @@ -name: Main +name: Build and Deploy + on: push: + branches: + - main pull_request: - -permissions: - contents: write - pull-requests: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + branches: + - main jobs: - validate: - name: Validate + build: runs-on: ubuntu-latest - steps: - - name: ⬇️ Checkout Repo - uses: actions/checkout@v4 - - - name: ⬢ Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '*' - cache: npm - - - name: 📦 Install Packages - run: npm ci - - name: 🧪 Test - run: npm test - - release: - name: Release - runs-on: ubuntu-latest - needs: [validate] - if: github.ref_name == 'main' && (github.event_name == 'push' || github.event.pull_request.merged) steps: - - name: ⬇️ Checkout Repo - uses: actions/checkout@v4 - - - name: ⬢ Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '*' - cache: npm + - name: Checkout repository + uses: actions/checkout@v2 - - name: 📦 Install Packages - run: npm ci + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' - - name: 🏗 Build - run: npm run build + - name: Install dependencies + run: npm install - - name: 🚀 Release - run: npx semantic-release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - dependabot: - name: Dependabot Auto-merge - runs-on: ubuntu-latest - needs: [validate] - if: github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' - steps: - - name: 💿 Dependabot metadata - id: metadata - uses: dependabot/fetch-metadata@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Build project + run: npm run build - - name: ↔️ Enable Auto-merge for minor and patch Dependabot PRs - run: gh pr merge --auto --squash "$PR_URL" - if: steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch' - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: purifier-card + path: dist/ diff --git a/package.json b/package.json index c564263..0a9c922 100644 --- a/package.json +++ b/package.json @@ -1,109 +1,22 @@ { "name": "purifier-card", "version": "1.0.0", - "description": "Air Purifier card for Home Assistant Lovelace UI", + "description": "A custom card for Home Assistant to control air purifiers", "main": "dist/purifier-card.js", "scripts": { - "start": "rollup -c --watch", - "lint": "eslint src", - "lint:fix": "eslint src --fix", - "format": "prettier --write .", - "build": "rollup -c", - "test": "npm run lint && npm run build", - "prepare": "husky" + "build": "rollup -c" }, - "keywords": [ - "home-assistant", - "homeassistant", - "hass", - "automation", - "lovelace", - "custom-cards", - "purifier" - ], - "author": "Denys Dovhan (http://denysdovhan.com/)", - "license": "MIT", "dependencies": { - "@types/lodash": "^4.14.195", - "custom-card-helpers": "^1.6.4", - "ha-template": "^1.2.2", - "home-assistant-js-websocket": "^9.1.0", - "lit": "^2.2.2", - "lodash": "^4.17.21" + "lit": "^2.0.0", + "lodash": "^4.17.21", + "ha-template": "^1.0.0" }, "devDependencies": { - "@babel/core": "^7.9.6", - "@babel/plugin-transform-runtime": "^7.17.0", - "@babel/preset-env": "^7.16.11", - "@rollup/plugin-babel": "^6.0.3", - "@rollup/plugin-commonjs": "^25.0.2", - "@rollup/plugin-image": "^3.0.1", - "@rollup/plugin-json": "^6.0.0", - "@rollup/plugin-node-resolve": "^15.0.1", - "@rollup/plugin-replace": "^5.0.2", - "@semantic-release/git": "^10.0.1", - "@typescript-eslint/eslint-plugin": "^5.59.11", - "@typescript-eslint/parser": "^5.59.11", - "eslint": "^8.14.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-import": "^2.20.2", - "husky": "^9.0.11", - "lint-staged": "^15.2.2", - "postcss-preset-env": "^9.1.2", - "prettier": "^3.2.5", - "rollup": "^2.7.6", - "rollup-plugin-html-literals": "^1.1.8", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-postcss-lit": "^2.0.0", - "rollup-plugin-serve": "^2.0.1", + "@rollup/plugin-commonjs": "^21.0.1", + "@rollup/plugin-node-resolve": "^13.1.1", + "rollup": "^2.56.3", "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-typescript2": "^0.36.0", - "semantic-release": "^24.0.0", - "typescript": "^5.1.3" - }, - "browserslist": [ - "last 2 versions", - "not dead" - ], - "lint-staged": { - "*.js": "eslint --fix", - "**/*": "prettier --write --ignore-unknown" - }, - "prettier": { - "singleQuote": true - }, - "release": { - "branches": [ - "main" - ], - "plugins": [ - [ - "@semantic-release/commit-analyzer", - { - "preset": "angular", - "releaseRules": [ - { - "type": "chore", - "scope": "deps", - "release": "patch" - } - ] - } - ], - "@semantic-release/release-notes-generator", - "@semantic-release/npm", - [ - "@semantic-release/github", - { - "assets": [ - { - "path": "dist/purifier-card.js", - "label": "purifier-card.js" - } - ] - } - ], - "@semantic-release/git" - ] + "rollup-plugin-typescript2": "^0.31.1", + "typescript": "^4.3.5" } -} +} \ No newline at end of file diff --git a/rollup.config.mjs b/rollup.config.mjs index 8e05076..c6ccd95 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,79 +1,21 @@ -/* eslint-env node */ -import { createRequire } from 'node:module'; -import commonjs from '@rollup/plugin-commonjs'; -import nodeResolve from '@rollup/plugin-node-resolve'; -import json from '@rollup/plugin-json'; import typescript from 'rollup-plugin-typescript2'; -import babel from '@rollup/plugin-babel'; -import image from '@rollup/plugin-image'; -import postcss from 'rollup-plugin-postcss'; -import postcssPresetEnv from 'postcss-preset-env'; -import postcssLit from 'rollup-plugin-postcss-lit'; +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; import { terser } from 'rollup-plugin-terser'; -import minifyLiterals from 'rollup-plugin-html-literals'; -import replace from '@rollup/plugin-replace'; -import serve from 'rollup-plugin-serve'; - -const require = createRequire(import.meta.url); -const pkg = require('./package.json'); - -const IS_DEV = process.env.ROLLUP_WATCH; - -const serverOptions = { - contentBase: ['./dist'], - host: 'localhost', - port: 5000, - allowCrossOrigin: true, - headers: { - 'Access-Control-Allow-Origin': '*', - }, -}; - -const plugins = [ - nodeResolve(), - commonjs(), - json(), - replace({ - values: { - PKG_VERSION_VALUE: IS_DEV ? 'DEVELOPMENT' : pkg.version, - }, - preventAssignment: true, - }), - postcss({ - plugins: [ - postcssPresetEnv({ - stage: 1, - features: { - 'nesting-rules': true, - }, - }), - ], - extract: false, - }), - postcssLit(), - image(), - typescript(), - babel({ - babelHelpers: 'runtime', - exclude: 'node_modules/**', - }), - IS_DEV && serve(serverOptions), - !IS_DEV && minifyLiterals(), - !IS_DEV && - terser({ - output: { - comments: false, - }, - }), -]; +import css from 'rollup-plugin-import-css'; export default { input: 'src/purifier-card.ts', output: { - dir: 'dist', + file: 'dist/purifier-card.js', format: 'es', - inlineDynamicImports: true, + sourcemap: true, }, - context: 'window', - plugins, + plugins: [ + resolve(), + commonjs(), + typescript({ tsconfig: './tsconfig.json' }), + terser(), + css() + ], };