Skip to content

Commit

Permalink
chore(ci): add release scripts and pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywu6 committed Aug 21, 2023
1 parent 9348e43 commit 60b5cda
Show file tree
Hide file tree
Showing 16 changed files with 860 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package repos, or single-package repos to help you version and publish your code. You can find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"bumpVersionsWithWorkspaceProtocolOnly": true
}
61 changes: 61 additions & 0 deletions .github/actions/ci-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'CI setup'
description: 'Setup CI environment'

inputs:
node-version:
description: 'Node version'
required: false
default: '16.20.x'
python-version:
description: 'Python version'
required: false
default: '3.8.x'
job-name:
description: 'Job name. Used to cache Nx results'
required: false
default: 'unknown-job'

runs:
using: 'composite'

steps:
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ^8.6.0
run_install: false

- name: Setup Node ${{ inputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
cache: 'pnpm'

- name: Setup Python ${{ inputs.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements.lock
requirements-dev.lock
- name: Setup Nx cache
uses: actions/cache@v3
with:
path: node_modules/.cache/nx
# Including SHA in the key causes a cache miss with every commit
# This is desired because we want cache results to always be updated
# while we will be using restore-keys to select the closest cache
key: cache-nx-${{ github.ref }}-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.node-version }}-${{ inputs.job-name }}-${{ github.sha }}
restore-keys: |
cache-nx-${{ github.ref }}-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.node-version }}-${{ inputs.job-name }}
cache-nx-${{ github.ref }}-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.node-version }}
cache-nx-${{ github.ref }}-${{ runner.os }}-${{ inputs.python-version }}
cache-nx-${{ github.ref }}-${{ runner.os }}
cache-nx-${{ github.ref }}
- name: Setup projects
shell: bash
run: pnpm bootstrap
99 changes: 61 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Code: CI'
name: CI

on:
pull_request:
Expand All @@ -11,63 +11,86 @@ on:
branches:
- main

permissions:
contents: read
actions: read # required by nrwl/nx-set-shas

jobs:
ci:
lint:
name: 'Lint'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# fetch the full history for Nx to determine affected projects
fetch-depth: 0
- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: 'main'

- uses: ./.github/actions/ci-setup
with:
job-name: 'lint'

- name: Lint
run: pnpm exec nx affected --target=lint:prettier,lint

test-js:
name: 'Test JavaScript: Node ${{ matrix.node-version }}'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['16.20.x']
python-version: ['3.8.16', '3.9.x', '3.10.x']

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: nrwl/nx-set-shas@v3
# https://nx.dev/recipes/ci/monorepo-ci-github-actions
# https://github.com/marketplace/actions/nx-set-shas
with:
main-branch-name: 'main'

- name: Use Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
- uses: ./.github/actions/ci-setup
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements.lock
requirements-dev.lock
job-name: 'test-js'
node-version: ${{ matrix.node-version }}

- name: Use PNPM
uses: pnpm/action-setup@v2
with:
version: ^8.6.0
run_install: false
- name: Test
run: pnpm exec nx affected --target=test:vitest

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
test-py:
name: 'Test Python: Python ${{ matrix.python-version }}'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8.x', '3.9.x', '3.10.x']

steps:
- uses: actions/checkout@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
fetch-depth: 0
- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: 'main'

- name: Cache Nx output
uses: actions/cache@v3
- uses: ./.github/actions/ci-setup
with:
path: node_modules/.cache/nx
key: |
cache-nx
-${{ runner.os }}
-${{ matrix.node-version }}
-${{ matrix.python-version }}
-${{ github.ref }}
job-name: 'test-py'
python-version: ${{ matrix.python-version }}

- name: Setup projects
run: pnpm bootstrap
- name: Test
run: pnpm exec nx affected --target=test:pytest

- name: Run linters and tests
run: pnpm run ci:affected
docker-image:
name: 'Build Docker image'
runs-on: ubuntu-latest
steps:
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v4
with:
push: false
# FIXME: change this to the actual Dockerfile name
file: ./docker/example.Dockerfile
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# https://github.com/sveltejs/kit/blob/32afba695088b946aefe96da75b36de9b0667fbe/.github/workflows/release.yml
name: Release

on:
push:
branches:
- main

permissions: {}

jobs:
release:
# FIXME: change this to the canonical repo name
# prevents this action from running on forks
if: github.repository == 'example/example'
permissions:
contents: write # to create release (changesets/action)
pull-requests: write # to create pull request (changesets/action)
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
# fetch the full history for changesets to generate changelog
fetch-depth: 0

- uses: ./.github/actions/ci-setup

- name: Build
run: pnpm exec nx run-many --target=build --exclude docs,website

- name: Create release PR or publish packages
id: changesets
uses: changesets/action@v1
with:
# run changeset version to consume all changesets and bump versions
version: pnpm run version
# publish with Nx. won't call changeset publish but does call changeset tag
publish: pnpm run release
# commit message for the release commits
commit: 'chore: stage changes for next release'
# title of the release PR
title: 'chore: release'
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
'*': ['prettier --ignore-unknown --check'],
'*.{css,less}': ['stylelint'],
'*.{js,jsx,ts,tsx,mjs,mts,cjs,cts,mtsx,ctsx,mjsx,cjsx}': ['eslint'],
'*.{py,pyi}': ['black --check', 'ruff check'],
'*.{py,pyi}': ['black --check', 'ruff check', 'pyright'],
};
20 changes: 4 additions & 16 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@
// words - list of words to be always considered correct
"words": [
"aiofiles",
"algoliasearch",
"astd",
"awatch",
"bufbuild",
"dbaeumer",
"dumi",
"dumirc",
"fdpexpect",
"fdspawn",
"hlistcol",
"kuscia",
"mdast",
"mdclient",
"mdserver",
"mdxjs",
"MDXJSESM",
"nrwl",
"pbar",
"pbars",
Expand All @@ -31,16 +21,14 @@
"protoc",
"pypa",
"pyproject",
"pyright",
"remarkrc",
"scql",
"tablefmt",
"tgroup",
"thead",
"tqdm",
"unist",
"Vercel",
"webp",
"yuque"
"vercel",
"vitest",
"webp"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DOCKER_USERNAME ?= $(shell whoami)
# FIXME: change this to the desired Docker image name
APPLICATION_NAME ?= example

GIT_HASH ?= $(shell git log --format="%h" -n 1)

image:
docker buildx build \
--platform linux/amd64 \
-t ${DOCKER_USERNAME}/${APPLICATION_NAME}:${GIT_HASH} \
-f ./docker/example.Dockerfile .
1 change: 1 addition & 0 deletions docker/example.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM python:3.10-slim-bookworm AS node-setup
9 changes: 8 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// The actual commands are defined in the `scripts` section in each package's package.json
"targetDefaults": {
"setup": {
"outputs": ["{projectRoot}/dist"],
"outputs": ["{projectRoot}/dist", "{projectRoot}/.dumi/tmp"],
"dependsOn": ["^setup"]
},
"build": {
Expand All @@ -73,6 +73,9 @@
"lint:black": {
"inputs": [":python"]
},
"lint:pyright": {
"inputs": [":python"]
},
"lint:ruff": {
"inputs": [":python", ":ruff"]
},
Expand All @@ -83,6 +86,7 @@
"lint:prettier",
"lint:tsc",
"lint:black",
"lint:pyright",
"lint:ruff"
]
},
Expand All @@ -94,6 +98,9 @@
},
"test": {
"dependsOn": ["test:vitest", "test:pytest"]
},
"release": {
"dependsOn": ["^build", "^release", "build"]
}
},
"tasksRunnerOptions": {
Expand Down
Loading

0 comments on commit 60b5cda

Please sign in to comment.