Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Repository layout, Package build system and CI #1

Merged
merged 1 commit into from
Aug 11, 2023
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
36 changes: 36 additions & 0 deletions .documentation/Contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Development and Contributing

This repo provides scripts for automatically linking and unlinking local development copies to and from end user packages, and scripts for automatically building all packages that are relevant to do so.

## Repository info

Packages from this repository get published to Github Packages from their master branch states by an automatic CI workflow.
Packages which are supported for third party use get identically published to NPM under the @seventv scope.

## Developer tooling

This repository provides multiple tools to make co-development of packages easier.

- `yarn dev:link`: Links all of this repo's packages to your yarn config, so they can be manually linked into projects using `yarn link <package>`
- `yarn dev:unlink`: Unlinks all of this repo's packages from your yarn config
- `yarn dev:link-project <path to project>`: Links all packages which the specified project depends on to the local versions in this repo, specify the `--all` option to link every package in this repo to the target project, even if they are not dependencies.
- `yarn dev:unlink-project <path to project>`: Unlinks all packages which were previously linked to the specified project from this repo, specify the `--skip-reinstall` parameter to avoid refetching live versions of the packages after unlinking, if this is skipped you may need to manually run `yarn install --check-files` to ensure any dangling or old links get dropped, and yarn fetches packages that are no longer linked.
- `yarn dev:bump-project-locks <path to project>`: Automatically bumps any dependency packages from this repo in the specified project's `yarn.lock` file, does not modify project manifest only bumps the static version the lockfile locks to, to the most recent one which now satisfies the dependency's constraints.

## Workspaces

When new packages are created they should be defined in the `workspaces` field in the root `package.json` for the repository so that npm will resolve internal dependancies correctly.

## Package versioning

Internal packages should version themselves with semantic versioning.

Internal packages should only depend on MAJOR version numbers for other internal packages.

End User packages like Website and Extension should depend on MAJOR and MINOR versions but not PATCH versions.

Major versions should be bumped when packages have breaking changes or otherwise change their shape in a way that breaks or requires changes in other component internal packages.

Minor versions should be bumped when packages change their shape, or otherwise change their implementation details, but not in a way that requires other internal components to be updated.

Patch versions should not be bumped manually, the CI builder should automatically publish a package to the next available patch number whenever a new commit is pushed to the master branch.
38 changes: 38 additions & 0 deletions .documentation/Package Publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CI Package Publishing Workflow

The CI should execute the following, either when a commit is pushed to the `master` branch or when manually triggered.

## Marking packages which need to be published

- Pull current `master` branch.
- Scan all top level directories of the repository, which do not start with a `.`, and contain a `package.json` in their root.
- For each matched directory recursively find the latest commit which modified it or any of its contents.
- For each matched directory parse its package manifest and note it's version.
- For each package, fetch the latest metadata from the Github Packages registry, finding the highest version that matches the local manifest's MAJOR and MINOR version.
- For each package find the timestamp the version was built and compare it to the commit date of the latest local commit for that package, if the last commit is newer or no published versions match, mark the package for publishing.

## Publishing marked packages

_Repeat for each package to be published_

- If the local manifest specifies the non standard flag `webComponentConfig.pinnedVersion` or defines a non-zero PATCH number, and a published version matched that number, skip this package and do nothing.
- Otherwise if the package does not meet the above criteria, and a published version was matched, increment the PATCH number by one higher than the published version's PATCH number and store it to the local manifest, but do not commit it to the repository.
- Create a new git tag in the repository at the latest local commit for the package, named with the format `<PACKAGE>@<VERSION>`.
- If the local manifest does not define a license string, copy the global license for this repository located in LICENSE.md to the package's root directory, and change the string to `SEE LICENSE IN LICENSE.md` and store it in the local manifest.
- If the package has a build step, install all of its dependancies.
- Build or transpile the package if neccissary or relevant to do so depending on the package.
- Publish the package to the Github Packages repository using the workflow's auth token.
- If the package specifies the non standard flag `webComponentConfig.dualPublish`, modify the local manifest and point the registry to the standard NPM Registry, ensuring access is set to public, and publish the package using the same version number and build results as published on Github Packages. Silently fail if a package with that version already exists.

## Github Packages cleanup (Optional)

_If implemented, the CI should execute the following either after every Publish cycle, or alternatively on a timer._

- Pull current `master` branch.
- Query the Github Packages API for every package linked to this repository.
- Enumerate every published version of selected packages.
- Scan the local repository for known packages, using the same process described in the [Marking for publish](#marking-packages-which-need-to-be-published) procedure.
- Find all versions which are NOT the highest PATCH version for any given MAJOR and MINOR version.
- For any packages which are currently known in the local repository, IGNORE all PATCH versions from the highest TWO MAJOR versions.
- For any versions which match the above criteria, and are not to be ignored, delete the package versions from the GitHub Packages registry.
- Always leave the git tags assigned to each PATCH version, even after their packages are deleted. Never revoke packages from the NPM registry.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yaml,yml}]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
40 changes: 40 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
root: true,
env: {
browser: true,
node: true,
es2021: true,
},
plugins: ["prettier"],
extends: [
"plugin:vue/vue3-recommended",
"eslint:recommended",
"@vue/typescript/recommended",
// Add under other rules
"@vue/prettier",
],
parserOptions: {
ecmaVersion: 2021,
},
ignorePatterns: ["locale/*.ts"],
rules: {
"prettier/prettier": "error",
"no-console": "warn",
"no-debugger": "error",
"no-undef": "off",
quotes: [1, "double"],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-namespace": "off",
"vue/valid-template-root": "off",
"vue/multi-word-component-names": "off",
"vue/require-default-prop": "off",
"vue/no-dupe-keys": "off",
"@typescript-eslint/no-non-null-assertion": "off",
},
globals: {
defineEmits: "readonly",
defineProps: "readonly",
NodeJS: "readonly",
},
};
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Versioning

- [ ] Includes breaking changes **(Requires major version bump)**
- [ ] Includes changes which modify the shape of the exposed api, in a non breaking way _(Internal packages don't need to be updated)_ **(Requires minor version bump)**
- [ ] If relevant, version has been bumped
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "Lint and Publish Updated Packages"

on:
push:
branches:
- master

pull_request:
types:
- opened
- synchronize
- reopened
- labeled

workflow_dispatch:
inputs:
publish:
type: boolean
default: false
description: "Run package publisher"

jobs:
lint:
name: Lint Packages
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup node auth and module cache
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: "19.x"
registry-url: "https://npm.pkg.github.com"

- name: Install Dependencies
run: yarn

- name: Lint all Packages
run: yarn lint

publish:
name: Publish Updated Packages
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
needs: [lint]
concurrency:
group: ${{ github.workflow }}-publish-${{ github.ref }}
cancel-in-progress: true
if: ${{ (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master') || (github.event_name == 'workflow_dispatch' && inputs.publish) }}

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
# Magic number (0x7fffffff) that tells git to fetch the entire history for just this ref, actions/checkout@v3 fetches all extraneous branches with depth 0
fetch-depth: 2147483647

- name: Set Git Author Credentials
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com

- name: Setup node auth and module cache
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: "19.x"
registry-url: "https://npm.pkg.github.com"

- name: Install Dependencies
run: yarn

- name: Check for and publish updated packages
run: yarn ci:publisher
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
*/logs
*/*.log
*/npm-debug.log*
*/yarn-debug.log*
*/yarn-error.log*
*/pnpm-debug.log*
*/lerna-debug.log*

node_modules
.DS_Store
*/node_modules
*/.DS_Store
*/dist
*/dist-ssr
*/coverage
**/*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
*/.vscode/*
!*/.vscode/extensions.json
!*/.vscode/settings.json
*/.idea
*/*.suo
*/*.ntvs*
*/*.njsproj
*/*.sln
*/*.sw?
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@seventv:registry=https://npm.pkg.github.com
Empty file added .npmrc.rev
Empty file.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*/dist
/node_modules
*/node_modules
26 changes: 26 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"trailingComma": "all",
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": false,
"printWidth": 120,
"importOrder": [
"^vue",
"^@vueuse/(.*)$",
"^pinia",
"^@/store/(.*)$",
"^@/common/(.*)$",
"^@/db/(.*)$",
"^@/composable/(.*)$",
"^@/site/(.*)$",
"^@/worker/(.*)$",
"^@/assets/(.*)$",
"^./(.*)$",
"<THIRD_PARTY_MODULES>"
],
"importOrderGroupNamespaceSpecifiers": true,
"importOrderSeparation": false,
"importOrderSortSpecifiers": true
}
Loading