Skip to content

Commit

Permalink
feat(ci): various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Apr 3, 2022
1 parent 8dd2749 commit 1496587
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 63 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/ci_demo-app.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
name: Deploy demo-app to GitHub Pages
name: Deploy demo-app

on:
push:
branches:
- main
tags-ignore:
- '**'
- '**'
paths-ignore:
- 'projects/site/**'
- 'projects/site/**'
workflow_dispatch:

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

jobs:
ci_demo-app:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16
registry-url: https://registry.npmjs.org/
cache: npm
- name: Make sure npm is latest

- name: Install latest npm
run: npm install -g npm@latest

- name: Install dependencies
run: npm clean-install
- name: Lint

- name: Lint demo apps
run: npm run lint:demo-app

- name: Build demo-app-auth-js
env:
baseUrl: /${{ github.event.repository.name }}/demo-app/auth-js/
run: npm run build:demo-app-auth-js -- --base-href=${{ env.baseUrl }} --deploy-url=${{ env.baseUrl }}

- name: Build demo-app-ngx-auth
env:
baseUrl: /${{ github.event.repository.name }}/demo-app/ngx-auth/
run: npm run build:demo-app-ngx-auth -- --base-href=${{ env.baseUrl }} --deploy-url=${{ env.baseUrl }}

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
41 changes: 26 additions & 15 deletions .github/workflows/ci_publish.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
name: Publish library to NPM
name: Publish libraries

on:
release:
types: [created]
workflow_dispatch:

jobs:
#ci_tests_and_build:
# uses: ./.github/workflows/ci_tests.yml

ci_publish:
#needs: ci_tests_and_build
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16
registry-url: https://registry.npmjs.org/
- name: Make sure npm is latest
cache: npm

- name: Install latest npm
run: npm install -g npm@latest

- name: Install dependencies
run: npm clean-install
- name: Lint
run: npm run lint
- name: Test
run: npm run test
- name: Build
run: npm run build:lib
# - name: Publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# run: npm publish ./dist --access=public

- name: Build auth-js
run: npm run build:auth-js

- name: Build ngx-auth
run: npm run build:ngx-auth

- name: Run semantic-release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx multi-semantic-release --ignore-packages="projects/demo-e2e/**"
20 changes: 15 additions & 5 deletions .github/workflows/ci_site.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
name: Deploy site to GitHub Pages
name: Deploy site

on:
push:
branches:
- main
tags-ignore:
- '**'
paths:
- '.github/workflows/ci_site.yml'
- 'projects/site/**'
tags-ignore:
- '**'
workflow_dispatch:

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

jobs:
ci_site:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16
registry-url: https://registry.npmjs.org/
cache: npm
- name: Make sure npm is latest
cache-dependency-path: projects/site/package-lock.json

- name: Install latest npm
run: npm install -g npm@latest

- name: Build site
working-directory: projects/site
run: |
npm clean-install
npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
44 changes: 36 additions & 8 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
name: CI tests
name: Run tests

on:
push:
branches:
- '**'
- '**'
tags-ignore:
- '**'
- '**'
paths-ignore:
- 'projects/site/**'
- 'projects/site/**'
pull_request:
workflow_call:
workflow_dispatch:

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

jobs:
ci_tests:
name: Tests on linux node${{ matrix.node }}
runs-on: ubuntu-latest
name: Tests on ${{ matrix.os }} node${{ matrix.node }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: ['12', '14', '16']
os: [ubuntu-latest, macos-latest, windows-latest]
node: [12, 14, 16]

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
registry-url: https://registry.npmjs.org/
- name: Make sure npm is latest
cache: npm

# https://github.com/actions/setup-node/issues/411
# https://github.com/npm/cli/issues/4341
- name: Workaround for npm installation on Windows
if: ${{ matrix.os == 'windows-latest' }}
run: npm install -g [email protected]

- name: Install latest npm
run: npm install -g npm@latest

- name: Install dependencies
run: npm clean-install

- name: Lint
run: npm run lint

# - name: Test
# run: npm run test

- name: Build auth-js
run: npm run build:auth-js

- name: Build ngx-auth
run: npm run build:ngx-auth
10 changes: 0 additions & 10 deletions .releaserc.json

This file was deleted.

21 changes: 21 additions & 0 deletions projects/auth-js/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"branches": [
"master",
{
"name": "main",
"channel": "beta",
"prerelease": "beta"
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "../../dist/auth-js"
}
],
"@semantic-release/github"
]
}
51 changes: 38 additions & 13 deletions projects/auth-js/build.js → projects/auth-js/build.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env node
const { buildSync } = require('esbuild');
const { exec } = require('child_process');
const { resolve: pathResolve } = require('path');
const { writeFileSync } = require('fs');
const { blue, green } = require('chalk');
const { dependencies, peerDependencies } = require(pathResolve(__dirname, 'package.json'));

import chalk from 'chalk';
import { exec } from 'child_process';
import cpy from 'cpy';
import { buildSync } from 'esbuild';
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import { dirname, resolve as pathResolve } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const { blue, green } = chalk;
const { dependencies, peerDependencies } = JSON.parse(readFileSync('package.json'));

const EXTERNALS = Object.keys({ ...dependencies, ...peerDependencies });
const DIST_PATH = pathResolve(__dirname, '../../dist/auth-js');
Expand All @@ -21,8 +27,7 @@ const execCmd = (cmd, opts) => new Promise((resolve, reject) => {

const build = async (entryPointName, platform, distName, bundleExternals = false, minify = false) => {
const outdir = pathResolve(DIST_PATH, distName, entryPointName);

buildSync({
const options = {
platform,
absWorkingDir: __dirname,
outfile: pathResolve(outdir, (minify) ? 'index.min.js' : 'index.js'),
Expand All @@ -33,20 +38,24 @@ const build = async (entryPointName, platform, distName, bundleExternals = false
minify,
globalName: (bundleExternals) ? 'AuthJS' : undefined,
external: (bundleExternals) ? undefined : EXTERNALS
});
};

mkdirSync(outdir, { recursive: true });
if (platform === 'neutral') {
options.mainFields = ['module', 'main'];
writeFileSync(pathResolve(outdir, 'package.json'), JSON.stringify({ type: 'module' }, null, 4), { encoding: 'utf8' });
} else if (platform === 'node') {
writeFileSync(pathResolve(outdir, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 4), { encoding: 'utf8' });
}

buildSync(options);
};

(async () => {
try {
console.log(blue('Building Library\n'));

// Build
// Build entry points
for (const entryPointName of ['core', 'oidc']) { // eslint-disable-line no-loops/no-loops
console.log('-'.repeat(78));
console.log(`Building entry point '@badisi/auth-js/${entryPointName}'`);
Expand All @@ -67,12 +76,28 @@ const build = async (entryPointName, platform, distName, bundleExternals = false
console.log(`${green('✓')} Built @badisi/auth-js/${entryPointName}`, '\n');
}

// Building types
// Build library
console.log('-'.repeat(78));
console.log('Building types for \'@badisi/auth-js\'');
console.log('Building \'@badisi/auth-js\'');
console.log('-'.repeat(78));
// types
await execCmd('tsc --project tsconfig.lib.json', { cwd: __dirname });
console.log(`${green('✓')} Built types\n`);
console.log(`${green('✓')} Generating types`);
// assets
await cpy('projects/auth-js/oidc/assets', pathResolve(DIST_PATH, 'oidc', 'assets'), { flat: true });
await cpy('projects/auth-js/package.json', DIST_PATH, { flat: true });
await cpy('projects/auth-js/README.md', DIST_PATH, { flat: true });
await cpy('LICENSE', DIST_PATH, { flat: true });
console.log(`${green('✓')} Copying assets`);
// package.json
const pkgJsonPath = pathResolve(DIST_PATH, 'package.json');
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, { encoding: 'utf8' }));
delete pkgJson.scripts;
delete pkgJson.devDependencies;
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), { encoding: 'utf8' });
console.log(`${green('✓')} Writing package metadata`);
// end
console.log(`${green('✓')} Built @badisi/auth-js\n`);

// Success
console.log(green('-'.repeat(78)));
Expand Down
3 changes: 3 additions & 0 deletions projects/auth-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"devDependencies": {
"@types/lodash-es": "^4.17.6"
},
"publishConfig": {
"access": "public"
},
"exports": {
"core": {
"import": "./esm/core/index.js",
Expand Down
7 changes: 1 addition & 6 deletions projects/auth-js/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
],
"options": {
"commands": [
"node projects/auth-js/build",
"cpy projects/auth-js/oidc/assets dist/auth-js/oidc/assets --flat",
"cpy projects/auth-js/package.json dist/auth-js/ --flat",
"cpy projects/auth-js/README.md dist/auth-js/ --flat",
"cpy LICENSE dist/auth-js/ --flat"
"node projects/auth-js/build.mjs"
],
"parallel": false,
"color": true
}
},
Expand Down
2 changes: 2 additions & 0 deletions projects/demo-e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"name": "demo-e2e",
"private": true,
"scripts": {
"start": "wdio run wdio.config.ts --debug=true --headless=true --watch=false"
},
Expand Down
Loading

0 comments on commit 1496587

Please sign in to comment.