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

ci: merge ci and release workflow #37

Merged
merged 11 commits into from
Aug 1, 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
20 changes: 10 additions & 10 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/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/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": ["@changesets/cli/commit", { "skipCI": false }],
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["demo"]
}
176 changes: 169 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 }}
50 changes: 0 additions & 50 deletions .github/workflows/release.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
}
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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).
The source code in this repository is licensed under [MIT](https://github.com/scalar/snippetz/blob/main/LICENSE).
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Snippetz / Opinionated HTTP Snippets</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌐</text></svg>">
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌐</text></svg>"
/>
</head>
<body>
<div id="app"></div>
Expand Down
2 changes: 2 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading
Loading