Skip to content

Commit

Permalink
ci: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Jul 10, 2024
1 parent 0c97e68 commit 07f3b10
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 112 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/ci_publish.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release library

on:
release:
types: [created]

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

ci_release:
needs: ci_tests
uses: dsi-hug/actions/.github/workflows/action.yml@v2
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
working-directory: projects/library
release: true
82 changes: 17 additions & 65 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,50 @@
name: Run tests

on:
workflow_dispatch:
workflow_call:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
workflow_call:
workflow_dispatch:

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

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

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
node: [18, 20]

name: ${{ matrix.os }}_node${{ matrix.node }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://registry.npmjs.org/
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 global dependencies
run: npm install -g npm@latest http-server

- name: Install latest Chrome (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
$ChromeInstallerFile = "googlechromestandaloneenterprise64.msi"
$ChromeInstallerUrl = "https://dl.google.com/tag/s/dl/chrome/install/${ChromeInstallerFile}"
$ChromeInstallerPath = Join-Path -Path "${env:Temp}" -ChildPath $ChromeInstallerFile
(New-Object System.Net.WebClient).DownloadFile($ChromeInstallerUrl, $ChromeInstallerPath)
Start-Process -FilePath msiexec.exe -ArgumentList "/i $ChromeInstallerPath /QN /norestart" -Wait -PassThru
- name: Install latest Chrome (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Install latest Chrome (macOS)
if: ${{ runner.os == 'macOS' }}
run: |
wget -q https://dl.google.com/chrome/mac/universal/stable/GGRO/googlechrome.dmg
hdiutil attach -quiet -noautofsck -noautoopen googlechrome.dmg
sudo cp -r /Volumes/Google\ Chrome/Google\ Chrome.app /Applications/
- name: Cache node_modules
uses: actions/cache@v4
id: cache-step
- name: Setup
uses: dsi-hug/actions/setup@v2
with:
key: cache-${{ matrix.os }}-node${{ matrix.node }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
cache-${{ matrix.os }}-node${{ matrix.node }}-
path: |
node_modules
- name: Install dependencies
if: steps.cache-step.outputs.cache-hit != 'true'
run: npm clean-install --engine-strict
node-version: ${{ matrix.node }}
setup-chrome: true

- name: Build tests application
run: npm run build:tests-app
working-directory: projects/tests-app
run: npm run build

- name: Serve tests application
working-directory: dist/tests-app
shell: bash # use bash because powershell is used by default on Windows and background job are cleaned after the run
run: http-server --port=4200 &
# use global install (instead of npx) because otherwise the server won't stay up on Windows
run: |
npm install -g http-server
http-server --port=4200 &
- name: Make sure tests application is running
shell: bash # use bash so that sleep is recognized even on Windows
run: sleep 5 && curl http://localhost:4200 -I

- name: Run tests
run: npm run start:tests-e2e -- -- --watch=false --debug=false --headless=true
working-directory: projects/tests-e2e
run: npm run start -- --watch=false --debug=false --headless=true
9 changes: 6 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ You can test the library while developing it, as follow:
1. Start the testing application

```sh
npm run start:tests-app
cd <project_path>/tests-app
npm run start
```

2. Make any modifications
Expand All @@ -36,15 +37,17 @@ You can test the library while developing it, as follow:
3. Run the tests

```sh
npm run start:tests-e2e
cd <project_path>/tests-e2e
npm run start
```

## Building the library

The library will be built in the `./dist` directory.

```sh
npm run build:lib
cd <project_path>/library
npm run build
```

## Publishing to NPM repository
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
],
"private": true,
"scripts": {
"ncu": "npx npm-check-updates -i --format=group --packageFile '{,projects/**/}package.json'",
"start:tests-app": "ng serve",
"start:tests-e2e": "npm run start --prefix=projects/tests-e2e",
"build:lib": "npm run build --prefix=projects/library",
"build:tests-app": "ng build"
"ncu": "npx npm-check-updates -i --format=group --packageFile '{,projects/**/}package.json'"
},
"workspaces": [
"projects/library",
"projects/tests-app",
"projects/tests-e2e"
],
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions projects/library/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const customizePackageJson = () => {
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, { encoding: 'utf8' }));
delete pkgJson.scripts;
delete pkgJson.devDependencies;
delete pkgJson.publishConfig;
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), { encoding: 'utf8' });
};

Expand Down
6 changes: 5 additions & 1 deletion projects/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"webdriverio"
],
"scripts": {
"build": "node ./build.mjs"
"build": "node ./build.mjs",
"release": "npm publish ../../dist"
},
"engines": {
"node": "^16.14.0 || >=18.10.0"
Expand All @@ -54,5 +55,8 @@
"@wdio/logger": "^8.38.0",
"webdriverio": "^8.39.1",
"cpy": "^11.0.1"
},
"publishConfig": {
"access": "public"
}
}
8 changes: 8 additions & 0 deletions projects/tests-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "tests-app",
"private": true,
"scripts": {
"start": "ng serve",
"build": "ng build"
}
}

0 comments on commit 07f3b10

Please sign in to comment.