Skip to content

refactor: use sub-packages #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .autorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"plugins": [
"@restfulhead/auto-plugin-filter-by-workspace-path",
"npm"
],
"labels": [
{
"name": "release-major",
"changelogTitle": "💥 Major breaking Change",
"releaseType": "major",
"color": "#c5000b"
},
{
"name": "release-minor",
"changelogTitle": "🚀 Enhancement",
"releaseType": "minor",
"color": "#F9D0C4"
},
{
"name": "release-patch",
"changelogTitle": "🐛 Patch",
"releaseType": "patch",
"color": "#C2E0C6"
},
{
"name": "release-internal",
"changelogTitle": "🔩 Internal",
"releaseType": "patch",
"color": "#BFD4F2"
},
{
"name": "release-docs",
"changelogTitle": "📝 Documentation",
"releaseType": "patch",
"color": "#BFD4F2"
}
]
}
13 changes: 3 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}

- name: Setting up ${{ matrix.node-version }}
Expand All @@ -32,16 +31,10 @@ jobs:
run: npm ci

- name: Build
run: npm run build:prod
run: npm run build -ws

- name: Lint
run: npm run lint
run: npm run lint -ws

- name: Test
run: npm test

- name: Release preview
run: |
npx auto shipit --dry-run
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: npm test -ws
38 changes: 0 additions & 38 deletions .github/workflows/publish.yml

This file was deleted.

121 changes: 121 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Release
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
issues: write
pull-requests: write

on:
push:
branches:
- release

jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.git-ref }}

- name: Setup GIT
run: |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git config user.name "$GITHUB_ACTOR"

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "package-lock.json"
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
env:
CI: true
run: |
npm ci

- name: Get workspaces
id: get-workspaces
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT
ws=$(npm ls --omit=dev --depth 1 -json | jq -r '.dependencies[].resolved[11:]')
echo 'ws<<EOF' >> $GITHUB_OUTPUT
echo $ws >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

- name: Build workspaces
env:
CI: true
run: |
npm run build -ws

- name: Release workspaces
if: steps.get-workspaces.outputs.ws != ''
env:
CI: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
topdir=$(pwd)
for workspace in ${{ steps.get-workspaces.outputs.ws }}; do
if [ "$workspace" = "packages/azure-functions-openapi-validator-example" ]; then
echo "Skipping release for $workspace"
continue
fi

echo "Potentially going to version and release $workspace"
cd $workspace
mkdir .git

PCKG_NAME=`node -pe "require('./package.json').name"`
CUR_VERSION_NO=`node -pe "require('./package.json').version"`

FROM_PARAM=""
if [ "$CUR_VERSION_NO" != "0.0.0" ]; then
FROM_PARAM="--from ${PCKG_NAME}_v${CUR_VERSION_NO}"
fi

VERSION=`npx auto version $FROM_PARAM`
if [ ! -z "$VERSION" ]; then
echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping version"
npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM
npm version $VERSION -m "chore: bump release version to %s [skip ci]"
NEW_VERSION_NO=`node -pe "require('./package.json').version"`
git tag -d v$NEW_VERSION_NO
NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO
echo "Going to create a new release for $NEW_TAG"
git add -A
git commit -m "chore: release v$NEW_VERSION_NO [skip ci]"
git tag -a $NEW_TAG -m "chore: tag v$NEW_VERSION_NO [skip ci]"
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }}
IS_PRIVATE=`node -pe "require('./package.json').private"`
if [ "$IS_PRIVATE" != "true" ]; then
npm publish ./dist
echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package versioned and published"
fi
rm -rf .git
else
echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected."
fi

cd $topdir
done

- if: ${{ always() }}
name: Clean working directory
run: |
rm -r *
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jspm_packages/
dist
dist-test
out
tsconfig.tsbuildinfo

# Azure Functions artifacts
bin
Expand Down
28 changes: 25 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,36 @@
"preLaunchTask": "func: host start"
},
{
"name": "Unit test current file",
"name": "[ajv-openapi-request-response-validator] Unit test current file",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/ajv-openapi-request-response-validator",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["${relativeFile}", "--config", "${workspaceFolder}/jest.config.js", "--testTimeout", "300000", "--no-cache", "--runInBand", "--detectOpenHandles"],
"args": ["${relativeFile}", "--config", "./jest.debug.config.js", "--testTimeout", "300000", "--no-cache", "--runInBand", "--detectOpenHandles"],
"internalConsoleOptions": "openOnSessionStart",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"outFiles": ["./dist/**/*.js"],
"outputCapture": "std",
"smartStep": true,
"skipFiles": [
"<node_internals>/**",
"node_modules/**"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
},
{
"name": "[azure-functions-openapi-validator] Unit test current file",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/azure-functions-openapi-validator",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["${relativeFile}", "--config", "./jest.debug.config.js", "--testTimeout", "300000", "--no-cache", "--runInBand", "--detectOpenHandles"],
"internalConsoleOptions": "openOnSessionStart",
"sourceMaps": true,
"outFiles": ["./dist/**/*.js"],
"outputCapture": "std",
"smartStep": true,
"skipFiles": [
Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"azureFunctions.deploySubpath": "example",
"azureFunctions.deploySubpath": "packages/ajv-openapi-request-response-validator",
"azureFunctions.postDeployTask": "npm install (functions)",
"azureFunctions.projectLanguage": "TypeScript",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 4,
"azureFunctions.projectSubpath": "example",
"azureFunctions.projectSubpath": "packages/ajv-openapi-request-response-validator",
"azureFunctions.preDeployTask": "npm prune (functions)",

// Place your settings in this file to overwrite default and user settings.
Expand All @@ -27,7 +27,7 @@
"[json]": {
"editor.formatOnSave": true
},
"eslint.workingDirectories": ["example", "src", "test"],
"eslint.workingDirectories": [{ "mode": "auto" }],
"eslint.options": {
"resolvePluginsRelativeTo": "."
},
Expand Down
35 changes: 5 additions & 30 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"isBackground": true,
"dependsOn": "npm build (functions)",
"options": {
"cwd": "${workspaceFolder}/example"
"cwd": "${workspaceFolder}/packages/azure-functions-openapi-validator-example"
},
"presentation": {
"reveal": "always",
Expand All @@ -20,12 +20,9 @@
{
"type": "shell",
"label": "npm build (functions)",
"command": "npm run build",
"command": "npm run build -ws",
"dependsOn": "npm clean (functions)",
"problemMatcher": "$tsc",
"options": {
"cwd": "${workspaceFolder}/example"
},
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
Expand All @@ -34,11 +31,8 @@
},
{
"type": "shell",
"label": "npm install (functions)",
"command": "npm install",
"options": {
"cwd": "${workspaceFolder}/example"
},
"label": "npm clean (functions)",
"command": "npm run clean -ws",
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
Expand All @@ -48,26 +42,7 @@
{
"type": "shell",
"label": "npm prune (functions)",
"command": "npm prune --production",
"dependsOn": "npm build (functions)",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}/example"
},
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
"close": true
}
},
{
"type": "shell",
"label": "npm clean (functions)",
"command": "npm run clean",
"dependsOn": "npm install (functions)",
"options": {
"cwd": "${workspaceFolder}/example"
},
"command": "npm prune --prodcution",
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
Expand Down
Loading