Skip to content

Commit

Permalink
ci: run Windows tests with GitHub Actions instead of Appveyor
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 13, 2021
1 parent 4808e8b commit 533c43c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 51 deletions.
33 changes: 0 additions & 33 deletions .appveyor.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
name: Node.js v${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf true
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🚫💩 lint-staged ![GitHub Actions](https://github.com/okonet/lint-staged/workflows/CI/badge.svg) [![Build Status for Windows](https://ci.appveyor.com/api/projects/status/github/okonet/lint-staged?branch=master&svg=true)](https://ci.appveyor.com/project/okonet/lint-staged) [![npm version](https://badge.fury.io/js/lint-staged.svg)](https://badge.fury.io/js/lint-staged) [![Codecov](https://codecov.io/gh/okonet/lint-staged/branch/master/graph/badge.svg)](https://codecov.io/gh/okonet/lint-staged)
# 🚫💩 lint-staged ![GitHub Actions](https://github.com/okonet/lint-staged/workflows/CI/badge.svg) [![npm version](https://badge.fury.io/js/lint-staged.svg)](https://badge.fury.io/js/lint-staged) [![Codecov](https://codecov.io/gh/okonet/lint-staged/branch/master/graph/badge.svg)](https://codecov.io/gh/okonet/lint-staged)

Run linters against staged git files and don't let :poop: slip into your code base!

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"scripts": {
"cz": "git-cz",
"lint": "eslint .",
"pretest": "npm run lint",
"test": "jest --coverage",
"test:watch": "jest --watch"
},
Expand Down
25 changes: 18 additions & 7 deletions test/gitWorkflow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { writeFile } from '../lib/file'
import GitWorkflow from '../lib/gitWorkflow'
import { getInitialState } from '../lib/state'
import { createTempDir } from './utils/tempDir'
import { isWindowsActions } from './utils/gitHubActions'

jest.mock('../lib/file.js')
jest.unmock('execa')
Expand All @@ -19,7 +20,8 @@ let tmpDir, cwd
const appendFile = async (filename, content, dir = cwd) =>
fs.appendFile(path.resolve(dir, filename), content)

const readFile = async (filename, dir = cwd) => fs.readFile(path.resolve(dir, filename))
const readFile = async (filename, dir = cwd) =>
fs.readFile(path.resolve(dir, filename), { encoding: 'utf-8' })

/** Wrap execGit to always pass `gitOps` */
const execGit = async (args) => execGitBase(args, { cwd })
Expand All @@ -34,8 +36,6 @@ const initGitRepo = async () => {
await execGit(['commit', '-m initial commit'])
}

const isAppveyor = !!process.env.APPVEYOR

describe('gitWorkflow', () => {
beforeEach(async () => {
tmpDir = await createTempDir()
Expand All @@ -44,9 +44,7 @@ describe('gitWorkflow', () => {
})

afterEach(async () => {
if (!isAppveyor) {
await fs.remove(tmpDir)
}
await fs.remove(tmpDir)
})

describe('prepare', () => {
Expand Down Expand Up @@ -164,19 +162,32 @@ describe('gitWorkflow', () => {
}
`)
})

it('should checkout renamed file when hiding changes', async () => {
const gitWorkflow = new GitWorkflow({
gitDir: cwd,
gitConfigDir: path.resolve(cwd, './.git'),
})

const origContent = await readFile('README.md')
await execGit(['mv', 'README.md', 'TEST.md'])
await appendFile('TEST.md', 'added content')

gitWorkflow.partiallyStagedFiles = await gitWorkflow.getPartiallyStagedFiles()
const ctx = getInitialState()
await gitWorkflow.hideUnstagedChanges(ctx)
expect(await readFile('TEST.md')).toStrictEqual(origContent)

if (isWindowsActions()) {
/**
* @todo `git mv` in GitHub Windows runners seem to remove
* the ending line terminator in this case.
*/
const received = await readFile('TEST.md')
const normalized = received.trimEnd() + `\n`
expect(normalized).toStrictEqual(origContent)
} else {
expect(await readFile('TEST.md')).toStrictEqual(origContent)
}
})
})

Expand Down
14 changes: 6 additions & 8 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ const fixJsConfig = { config: { '*.js': 'prettier --write' } }
let tmpDir
let cwd

// Get file content
const readFile = async (filename, dir = cwd) =>
fs.readFile(path.resolve(dir, filename), { encoding: 'utf-8' })
// Get file content, coercing Windows `\r\n` newlines to `\n`
const readFile = async (filename, dir = cwd) => {
const file = await fs.readFile(path.resolve(dir, filename), { encoding: 'utf-8' })
return file.replace(/(\r\n|\r|\n)/gm, '\n')
}

// Append to file, creating if it doesn't exist
const appendFile = async (filename, content, dir = cwd) =>
Expand Down Expand Up @@ -83,8 +85,6 @@ describe('lint-staged', () => {

const globalConsoleTemp = console

const isAppveyor = !!process.env.APPVEYOR

describe('lint-staged', () => {
beforeAll(() => {
console = makeConsoleMock()
Expand All @@ -104,9 +104,7 @@ describe('lint-staged', () => {

afterEach(async () => {
console.clearHistory()
if (!isAppveyor) {
await fs.remove(tmpDir)
}
await fs.remove(tmpDir)
})

afterAll(() => {
Expand Down
4 changes: 4 additions & 0 deletions test/utils/gitHubActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const isWindowsActions = () => {
const { GITHUB_ACTIONS, RUNNER_OS } = process.env
return GITHUB_ACTIONS === 'true' && RUNNER_OS === 'Windows'
}
2 changes: 1 addition & 1 deletion test/utils/tempDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs-extra'
import os from 'os'
import path from 'path'

const osTmpDir = process.env.APPVEYOR ? 'C:\\projects' : fs.realpathSync(os.tmpdir())
const osTmpDir = fs.realpathSync(process.env.RUNNER_TEMP || os.tmpdir())

/**
* Create temporary random directory and return its path
Expand Down

0 comments on commit 533c43c

Please sign in to comment.