From 05bd2cdf8ec506441505c62755f2b249e6c2d8dc Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 1 Aug 2024 13:20:50 +0200 Subject: [PATCH] ci: merge ci and release workflow (#37) * refactor: update ci workflow * chore: remove old release workflow * chore: add missing tasks * fix: TS issue * chore: ignore vue TypeScript configuration issue * chore: update TS config * chore: add format and format:check scripts * chore: code style * fix: wrong test script * chore: add missing tsconfig * docs: remove release badge --- .changeset/config.json | 20 +- .github/workflows/ci.yml | 176 +++++++++++++++++- .github/workflows/release.yml | 50 ----- .prettierignore | 20 ++ .prettierrc | 2 +- README.md | 7 +- demo/index.html | 7 +- demo/package.json | 2 + demo/src/App.vue | 102 ++++++---- demo/src/components/CodeExample.vue | 33 ++-- demo/src/vite-env.d.ts | 1 - demo/tsconfig.json | 36 ++-- demo/tsconfig.node.json | 10 - demo/vite.config.ts | 28 +-- package.json | 11 +- packages/snippetz-core/tsconfig.build.json | 22 +-- packages/snippetz-core/tsconfig.json | 5 + .../tsconfig.build.json | 22 +-- .../snippetz-plugin-js-fetch/tsconfig.json | 5 + .../snippetz-plugin-js-ofetch/src/ofetch.ts | 2 +- .../tsconfig.build.json | 22 +-- .../snippetz-plugin-js-ofetch/tsconfig.json | 5 + .../tsconfig.build.json | 22 +-- .../snippetz-plugin-node-fetch/tsconfig.json | 5 + .../tsconfig.build.json | 22 +-- .../snippetz-plugin-node-ofetch/tsconfig.json | 5 + .../snippetz-plugin-node-undici/src/undici.ts | 4 +- .../tsconfig.build.json | 22 +-- .../snippetz-plugin-node-undici/tsconfig.json | 5 + packages/snippetz/src/snippetz.test.ts | 8 +- packages/snippetz/src/snippetz.ts | 4 +- packages/snippetz/tsconfig.build.json | 22 +-- packages/snippetz/tsconfig.json | 5 + tsconfig.json | 35 ++-- turbo.json | 10 +- 35 files changed, 478 insertions(+), 279 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .prettierignore delete mode 100644 demo/src/vite-env.d.ts delete mode 100644 demo/tsconfig.node.json create mode 100644 packages/snippetz-core/tsconfig.json create mode 100644 packages/snippetz-plugin-js-fetch/tsconfig.json create mode 100644 packages/snippetz-plugin-js-ofetch/tsconfig.json create mode 100644 packages/snippetz-plugin-node-fetch/tsconfig.json create mode 100644 packages/snippetz-plugin-node-ofetch/tsconfig.json create mode 100644 packages/snippetz-plugin-node-undici/tsconfig.json create mode 100644 packages/snippetz/tsconfig.json diff --git a/.changeset/config.json b/.changeset/config.json index 9539043..7d95688 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,11 +1,11 @@ { - "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": ["@changesets/cli/commit", { "skipCI": false }], - "fixed": [], - "linked": [], - "access": "public", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": ["demo"] - } + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": ["@changesets/cli/commit", { "skipCI": false }], + "fixed": [], + "linked": [], + "access": "public", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": ["demo"] +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76d8546..a53b148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,20 +1,96 @@ name: CI on: - pull_request: + push: branches: - main - push: + pull_request: branches: - main jobs: - lint: + # Always use Node 20 + # Add Node 18 to the matrix if we’re in the release PR + define-matrix: + runs-on: ubuntu-latest + + outputs: + node-versions: ${{ steps.node-versions.outputs.node-versions }} + + steps: + - name: Node version matrix + id: node-versions + run: | + if [ "${{ github.head_ref }}" == "changeset-release/main" ]; then + echo 'node-versions=[18, 20]' >> "$GITHUB_OUTPUT" + else + echo 'node-versions=[20]' >> "$GITHUB_OUTPUT" + fi + - name: Print Node version matrix + run: echo "node-versions=${{ steps.node-versions.outputs.node-versions }}" + - name: Check Node version matrix + run: | + if [ "${{ steps.node-versions.outputs.node-versions }}" != "[18, 20]" ] && [ "${{ steps.node-versions.outputs.node-versions }}" != "[20]" ]; then + echo "Node version matrix is not [18, 20] or [20]" + exit 1 + fi + + build: + runs-on: ubuntu-20.04 + needs: define-matrix + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - name: Update Turborepo cache + uses: actions/cache/save@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + + format: runs-on: ubuntu-20.04 strategy: matrix: node-version: [20] + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dev dependencies + run: pnpm install --dev + - name: Check code style + run: pnpm format:check + + types: + runs-on: ubuntu-20.04 + needs: [define-matrix, build] + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 @@ -26,8 +102,94 @@ jobs: - name: Install dependencies run: pnpm install - name: Turborepo cache - uses: dtinth/setup-github-actions-caching-for-turbo@v1 + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - if: matrix.node-version == 20 || github.head_ref == 'changeset-release/main' + name: Check types + run: pnpm turbo types:check + + test: + runs-on: ubuntu-20.04 + needs: [define-matrix, build] + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm build + - name: Run tests + run: pnpm test + + release: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-20.04 + permissions: + contents: write + id-token: write + needs: [build, test] + strategy: + matrix: + node-version: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - name: Git Status + run: git status + - name: Stash changes + run: git stash + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 with: - cache-prefix: snippetz - - name: Build & test - run: pnpm turbo test + # The pull request title. + title: 'chore: release' + # The command to update version, edit CHANGELOG, read and delete changesets. + version: 'pnpm changeset version' + # The commit message to use. + commit: 'chore: version packages' + # The command to use to build and publish packages + publish: 'pnpm -r publish --access public' + env: + # https://github.com/settings/tokens/new + # Expiration: No expiration + # Select: repo.* + GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + # https://www.npmjs.com/settings/YOUR_ACCOUNT_HANDLE/tokens/granular-access-tokens/new + # Custom Expiration: 01-01-2100 + # Permissions: Read and Write + # Select packages: @scalar + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 0473567..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Release - -on: - push: - branches: - - main - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -jobs: - release: - name: Release - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [20] - - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - - name: Install dependencies - run: pnpm install - - name: Turborepo cache - uses: dtinth/setup-github-actions-caching-for-turbo@v1 - with: - cache-prefix: snippetz - - name: Build & test - run: pnpm turbo test - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@v1 - with: - # The pull request title. - title: 'chore: release' - # The command to update version, edit CHANGELOG, read and delete changesets. - version: 'pnpm run bump' - # The commit message to use. - commit: 'chore: version packages' - # The command to use to build and publish packages - publish: 'pnpm -r publish --access public' - env: - GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b8c69db --- /dev/null +++ b/.prettierignore @@ -0,0 +1,20 @@ +**/.git +**/.svn +**/.hg +**/node_modules +**/dist/** +**/.turbo/** +**/build/** +**/.next/** +**/.nuxt/** + +/venv/ +**/venv +/.venv/ +**/.venv + +pnpm-lock.yaml +.changeset/*.md + +.vite-ssg-temp +.next diff --git a/.prettierrc b/.prettierrc index 66e7e94..fa51da2 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,4 +3,4 @@ "tabWidth": 2, "semi": false, "singleQuote": true -} \ No newline at end of file +} diff --git a/README.md b/README.md index c0f646f..ffc01e2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Snippetz [![CI](https://github.com/scalar/snippetz/actions/workflows/ci.yml/badge.svg)](https://github.com/scalar/snippetz/actions/workflows/ci.yml) -[![Release](https://github.com/scalar/snippetz/actions/workflows/release.yml/badge.svg)](https://github.com/scalar/snippetz/actions/workflows/release.yml) [![Contributors](https://img.shields.io/github/contributors/scalar/snippetz)](https://github.com/scalar/snippetz/graphs/contributors) [![GitHub License](https://img.shields.io/github/license/scalar/snippetz)](https://github.com/scalar/snippetz/blob/main/LICENSE) [![Version](https://img.shields.io/npm/v/%40scalar/snippetz)](https://www.npmjs.com/package/@scalar/snippetz) @@ -24,7 +23,7 @@ npm install @scalar/snippetz import { snippetz } from '@scalar/snippetz' const snippet = snippetz().print('node', 'undici', { - url: 'https://example.com' + url: 'https://example.com', }) /* Output */ @@ -73,7 +72,7 @@ const snippet = snippetz().hasPlugin('node', 'undici') import { undici } from '@scalar/snippetz-plugin-undici' const source = undici({ - url: 'https://example.com' + url: 'https://example.com', }) console.log(source.code) @@ -118,4 +117,4 @@ Contributions are welcome! Read [`CONTRIBUTING`](https://github.com/scalar/snipp ## License -The source code in this repository is licensed under [MIT](https://github.com/scalar/snippetz/blob/main/LICENSE). \ No newline at end of file +The source code in this repository is licensed under [MIT](https://github.com/scalar/snippetz/blob/main/LICENSE). diff --git a/demo/index.html b/demo/index.html index be6a137..2400ee6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,10 +1,13 @@ - + Snippetz / Opinionated HTTP Snippets - +
diff --git a/demo/package.json b/demo/package.json index cff62fe..ceca236 100644 --- a/demo/package.json +++ b/demo/package.json @@ -6,6 +6,8 @@ "scripts": { "dev": "vite", "build": "vue-tsc && vite build", + "types:build": "vue-tsc -p tsconfig.build.json", + "types:check": "vue-tsc --composite false", "preview": "vite preview" }, "dependencies": { diff --git a/demo/src/App.vue b/demo/src/App.vue index 0a931a7..914f774 100644 --- a/demo/src/App.vue +++ b/demo/src/App.vue @@ -1,70 +1,98 @@