Skip to content

Commit

Permalink
feat(configuration): show deployment files in CI and tests in workflow
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed May 22, 2024
1 parent 5419355 commit 205fecd
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- run: bun install
- run: bun check
- run: bun types
- run: bun test
- name: 📢 Release
uses: tobua/release-npm-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion configuration/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export const templates = {
export const extension = (path: string) => ({ extends: path })

export function createFile(configuration: object) {
return { name: 'vercel.json', contents: JSON.stringify(configuration, null, 2) }
return { name: 'vercel.json', contents: JSON.stringify(configuration, null, 2), showInCi: true }
}
7 changes: 5 additions & 2 deletions helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dirname, join } from 'node:path'
import { it } from 'avait'
import Bun from 'bun'
import glob from 'fast-glob'
import isCi from 'is-ci'
import { parse } from 'parse-gitignore'
import { merge } from 'ts-deepmerge'
import { z } from 'zod'
Expand Down Expand Up @@ -177,7 +178,9 @@ export function installLocalDependencies() {
}
}

export async function writeFile(file: File) {
export async function writeFile(file: File, ignores: string[]) {
await Bun.write(root(file.name), file.contents)
return file.name
if (!(file.showInCi && isCi)) {
ignores.push(file.name)
}
}
6 changes: 2 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ async function configureProject() {
if (!files) continue
if (Array.isArray(files)) {
for (const file of files.filter((item) => item?.name)) {
const name = await writeFile(file as File)
ignores.push(name)
await writeFile(file as File, ignores)
}
} else {
const name = await writeFile(files as File)
ignores.push(name)
await writeFile(files as File, ignores)
}
}

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
"dependencies": {
"avait": "^1.0.0",
"fast-glob": "^3.3.2",
"is-ci": "^3.0.1",
"logua": "^3.0.3",
"parse-gitignore": "^2.0.0",
"ts-deepmerge": "^7.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@types/bun": "^1.1.2",
"@types/bun": "^1.1.3",
"@types/is-ci": "^3.0.4",
"@types/parse-gitignore": "^1.0.2",
"eslint-config-airbnb": "^19.0.4",
"typescript": "^5.4.5"
Expand Down Expand Up @@ -78,7 +80,10 @@
"typescript": {
"compilerOptions": {
"target": "ES2022",
"lib": ["DOM", "ES2022"]
"lib": [
"DOM",
"ES2022"
]
},
"extends": "plugin",
"files": [
Expand Down
36 changes: 34 additions & 2 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, test } from 'bun:test'
import { execSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { existsSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import Bun from 'bun'

// To include additional files in fixtures remove the ignore entries temporarly from .gitignore in root and fixtures and add the specific files needed.

test('Adds configuration files for basic package setup.', () => {
test('Adds configuration files for basic package setup.', async () => {
const fixturePath = './test/fixture/package'

execSync('bun ./../../../index.ts', {
Expand All @@ -18,6 +18,13 @@ test('Adds configuration files for basic package setup.', () => {
expect(existsSync(join(fixturePath, '.prettierignore'))).toBe(true)
expect(existsSync(join(fixturePath, 'biome.json'))).toBe(true)
expect(existsSync(join(fixturePath, 'LICENSE.md'))).toBe(true)
expect(existsSync(join(fixturePath, 'vercel.json'))).toBe(true)
expect(existsSync(join(fixturePath, '.gitignore'))).toBe(true)

const gitignoreFile = await Bun.file(join(fixturePath, '.gitignore')).text()

expect(gitignoreFile).toContain('vercel.json')

Check failure on line 26 in test/basic.test.ts

View workflow job for this annotation

GitHub Actions / publish-release

error: expect(received).toContain(expected)

Expected to contain: "vercel.json" Received: "tsconfig.json\nbiome.json\neslint.config.js\nprettier.config.js\n.prettierignore\nplaywright.config.ts\nLICENSE.md\n" at /home/runner/work/zero-configuration/zero-configuration/test/basic.test.ts:26:3
expect(gitignoreFile).toContain('biome.json')
})

test('Adds configuration files for basic file setup.', async () => {
Expand Down Expand Up @@ -145,3 +152,28 @@ test('Will also install local dependencies if listed.', () => {
expect(existsSync(join(fixturePath, 'node_modules/keep/package.json'))).toBe(true)
expect(existsSync(join(fixturePath, 'node_modules/empty-dependency/package.json'))).toBe(true)
})

test("Doesn't add deployment files to gitignore in CI.", async () => {
const fixturePath = './test/fixture/package'

// TODO existing ignores should not be taken over.
rmSync(join(fixturePath, '.gitignore'))

execSync('bun ./../../../index.ts', {
cwd: fixturePath,
stdio: 'inherit',
env: {
...process.env,
// biome-ignore lint/style/useNamingConvention: Casing used by Node.js.
CI: 'true',
},
})

expect(existsSync(join(fixturePath, 'vercel.json'))).toBe(true)
expect(existsSync(join(fixturePath, '.gitignore'))).toBe(true)

const gitignoreFile = await Bun.file(join(fixturePath, '.gitignore')).text()

expect(gitignoreFile).not.toContain('vercel.json')
expect(gitignoreFile).toContain('biome.json')
})
2 changes: 1 addition & 1 deletion test/fixture/build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build",
"configuratidon": {
"configuration": {
"postcss": {
"plugins": {
"tailwindcss": {}
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"compilerOptions": {
"target": "ES6"
}
},
"vercel": {
"github": {
"silent": true
}
}
}
}
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PackageJson = {
configuration?: { [key: string]: string | object | string[] }
}

export type File = { name: string; contents: string }
export type File = { name: string; contents: string; showInCi?: boolean }

export type Configuration = {
name: ConfigurationKeys
Expand Down

0 comments on commit 205fecd

Please sign in to comment.