-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4efd0d1
commit 83469d8
Showing
13 changed files
with
1,345 additions
and
797 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { vi } from 'vitest'; | ||
|
||
import { mkdtemp, rm } from 'node:fs/promises'; | ||
import { tmpdir } from 'node:os'; | ||
import * as path from 'node:path'; | ||
|
||
import { Act } from '@kie/act-js'; | ||
|
||
const originalRun = Reflect.get(Act.prototype, 'run') as typeof run; | ||
|
||
// Ensure that a new cache entry is created each time | ||
vi | ||
.spyOn(Act.prototype, 'run' as keyof Act) | ||
.mockImplementation(run as ReturnType<typeof vi.fn>); | ||
|
||
// Prevent `act-js` from creating `.actrc` file in home directory | ||
vi | ||
.spyOn(Act.prototype, 'setDefaultImage' as keyof Act) | ||
.mockImplementation(vi.fn()); | ||
|
||
async function run( | ||
this: Act, | ||
cmd: string[], | ||
...args: unknown[] | ||
): Promise<unknown> { | ||
const tmp = await mkdtemp(path.join(tmpdir(), 'act-')); | ||
await using _ = { // eslint-disable-line @typescript-eslint/no-unused-vars | ||
async [Symbol.asyncDispose]() { | ||
await rm(tmp, { force: true, recursive: true }); | ||
}, | ||
}; | ||
console.error(`Using ${tmp} as cache server path`); | ||
cmd.push('--cache-server-path', tmp); | ||
return await originalRun.call(this, cmd, ...args); | ||
} | ||
|
||
export { Act }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { beforeEach, expect, test, vi } from 'vitest'; | ||
|
||
import * as path from 'node:path'; | ||
import { env } from 'node:process'; | ||
|
||
import { Act, type RunOpts } from '@kie/act-js'; | ||
|
||
vi.mock('@kie/act-js'); | ||
|
||
// Use the repository root as cwd: | ||
const cwd = env['npm_config_local_prefix'] | ||
?? path.resolve(import.meta.dirname, '../../../'); | ||
|
||
const job = 'test'; | ||
const workflow = path.resolve( | ||
import.meta.dirname, | ||
'../workflows/cache-on-failure.yml', | ||
); | ||
// Send logs to stderr: | ||
const opts = { logFile: '/dev/stderr' } as const satisfies RunOpts; | ||
|
||
const key = 'SETUP_TEXLIVE_ACTION_NO_CACHE_ON_FAILURE'; | ||
const msg = /^Cache saved successfully$/gmv; | ||
const act = new Act(cwd, workflow); | ||
|
||
beforeEach(() => { | ||
act.clearEnv(); | ||
}); | ||
|
||
test('default', async () => { | ||
const steps = await act.runJob(job, opts); | ||
expect(steps[1]?.name).toMatchSnapshot(); | ||
expect(steps[1]?.status).toBe(0); | ||
expect(steps[2]?.name).toMatchSnapshot(); | ||
expect(steps[2]?.status).toBe(0); | ||
expect(steps[3]?.status).toBe(1); | ||
expect(steps[4]?.name).toMatchSnapshot(); | ||
expect(steps[4]?.status).toBe(0); | ||
expect(steps[4]?.output).toMatch(msg); | ||
}); | ||
|
||
test('with-0', async () => { | ||
act.setEnv(key, '0'); | ||
const steps = await act.runJob(job, opts); | ||
expect(steps[1]?.name).toMatchSnapshot(); | ||
expect(steps[1]?.status).toBe(0); | ||
expect(steps[2]?.name).toMatchSnapshot(); | ||
expect(steps[2]?.status).toBe(0); | ||
expect(steps[3]?.status).toBe(1); | ||
expect(steps[4]?.name).toMatchSnapshot(); | ||
expect(steps[4]?.status).toBe(0); | ||
expect(steps[4]?.output).toMatch(msg); | ||
}); | ||
|
||
test.for(['1', 'true', ''])('with-%s', async (value) => { | ||
act.setEnv(key, value); | ||
const steps = await act.runJob(job, opts); | ||
expect(steps[1]?.name).toMatchSnapshot(); | ||
expect(steps[1]?.status).toBe(0); | ||
expect(steps[2]?.name).toMatchSnapshot(); | ||
expect(steps[2]?.status).toBe(0); | ||
expect(steps[3]?.status).toBe(1); | ||
expect(steps[4]).toBeUndefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { mergeConfig } from 'vitest/config'; | ||
|
||
import defaultConfig from '@setup-texlive-action/config/vitest'; | ||
|
||
export default mergeConfig(defaultConfig, { | ||
test: { | ||
testTimeout: 5 * 60 * 1000, // 5min | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
on: workflow_dispatch | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup TeX Live | ||
id: setup | ||
uses: ./ | ||
- name: Check that a new installation has been made | ||
run: exit ${{ fromJSON(steps.setup.outputs.cache-restored) || 1 && 0 }} | ||
- name: Always fails | ||
run: exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
["*/vitest.config.{js,mjs,ts}"] | ||
[ | ||
"*/vitest.config.{js,mjs,ts}", | ||
"!e2e/vitest.config.mjs" | ||
] |