Skip to content

Commit

Permalink
Update template repo after release
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Jan 6, 2024
1 parent 074b6ec commit 6a4c322
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 10 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout Master
uses: actions/checkout@v4
- uses: actions/checkout@v4

- uses: pnpm/[email protected]
with:
version: 8

- name: Use Node.js ${{ matrix.node-version }}
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
node-version: 18
cache: 'pnpm'

- name: Install Dependencies
run: pnpm i
run: pnpm i --frozen-lockfile

- name: Lint Format
run: pnpm lint:prettier
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
cache: 'pnpm'

- name: Install Dependencies
run: pnpm i
run: pnpm i --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
Expand All @@ -36,3 +36,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
UPDATE_TEMPLATE_SSH_KEY: ${{ secrets.UPDATE_TEMPLATE_SSH_KEY }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Unit Tests

on:
pull_request:
branches: [main, dev]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]

steps:
- uses: actions/checkout@v4

- uses: pnpm/[email protected]
with:
version: 8

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Install Dependencies
run: pnpm i --frozen-lockfile

- name: Run Tests
run: pnpm test
1 change: 1 addition & 0 deletions packages/create-next-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"clean": "rimraf dist",
"dev": "tsup --watch",
"lint": "eslint .",
"postpublish": "echo \"Updating template repo\" && bash ./scripts/update-git-repo.sh",
"types:check": "tsc --noEmit"
},
"dependencies": {
Expand Down
22 changes: 22 additions & 0 deletions packages/create-next-docs/scripts/update-git-repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from 'node:fs';
import path from 'node:path';
import { create } from '../dist/create-app.js';

const repo = process.argv[2] ?? './next-docs-ui-template';

fs.readdirSync(repo).forEach((file) => {
if (file !== '.git') {
fs.rmSync(path.join(repo, file), {
recursive: true,
force: true,
});
}
});

await create({
outputDir: repo,
template: 'next-docs-mdx',
tailwindcss: false,
installDeps: false,
packageManager: 'npm',
});
37 changes: 37 additions & 0 deletions packages/create-next-docs/scripts/update-git-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Inspired by Svelte Kit

get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}

DIR=$(get_abs_filename $(dirname "$0"))
TMP=$(get_abs_filename "$DIR/../node_modules/.tmp")

if [ "$CI" ]; then
(umask 0077; echo "$UPDATE_TEMPLATE_SSH_KEY" > ~/ssh_key;)
export GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new -i ~/ssh_key'
fi

mkdir -p $TMP
cd $TMP

# clone the template repo
rm -rf next-docs-ui-template
git clone --depth 1 --single-branch --branch main https://github.com/fuma-nama/next-docs-ui-template.git

# empty out the repo
cd next-docs-ui-template
node $DIR/update-git-repo.js $TMP/next-docs-ui-template

if [ "$CI" ]; then
git config user.email '[email protected]'
git config user.name '[bot]'
fi

# commit the new files
git add -A
git commit -m "version $npm_package_version"

git push https://github.com/fuma-nama/next-docs-ui-template.git main -f

0 comments on commit 6a4c322

Please sign in to comment.