Skip to content

Commit 31e58d0

Browse files
chore: Cherry-picked changes from upstream (#40)
* chore: add tests (#123) * chore: add tests (#123) * chore: add tests (#123) * chore: add tests (#123) * chore: add tests (#123) * chore: add tests (#123) * chore(deps): update dependency helmfile/vals to v0.41.1 (#124) * fix: apply code build script * fix: apply code build script * conflicted/workflow file cherry-picked manually * chore: dist updated (#42) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Raj-StepSecurity <[email protected]>
1 parent cbcb333 commit 31e58d0

File tree

13 files changed

+4810
-4725
lines changed

13 files changed

+4810
-4725
lines changed

.editorconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ root = true
33
[*]
44
charset = utf-8
55
indent_style = space
6-
indent_size = 4
6+
indent_size = 2
77
insert_final_newline = true
88
trim_trailing_whitespace = true
99
end_of_line = lf
1010
max_line_length = 160
1111

12-
[*.{yaml,yml,json}]
13-
indent_size = 2

.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ACTIONS_STEP_DEBUG=true
99

1010
# GitHub Actions inputs should follow `INPUT_<name>` format (case-sensitive).
1111
# Hyphens should not be converted to underscores!
12-
INPUT_MILLISECONDS=2400
12+
INPUT_VERSION=stable
1313

1414
# GitHub Actions default environment variables. These are set for every run of a
1515
# workflow and can be used in your actions. Setting the value here will override
1616
# any value set by the local-action tool.
1717
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
1818

19-
# CI="true"
19+
CI=true
2020
# GITHUB_ACTION=""
2121
# GITHUB_ACTION_PATH=""
2222
# GITHUB_ACTION_REPOSITORY=""
@@ -53,9 +53,9 @@ INPUT_MILLISECONDS=2400
5353
# GITHUB_WORKFLOW_REF=""
5454
# GITHUB_WORKFLOW_SHA=""
5555
# GITHUB_WORKSPACE=""
56-
# RUNNER_ARCH=""
56+
RUNNER_ARCH=X64
5757
# RUNNER_DEBUG=""
5858
# RUNNER_NAME=""
59-
# RUNNER_OS=""
59+
RUNNER_OS=Linux
6060
RUNNER_TEMP=.local/tmp
6161
RUNNER_TOOL_CACHE=.local/cache

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
env:
2-
RUNNER_DEBUG: 1
3-
41
name: 'CI'
52
on: # rebuild any PRs and main branch changes
63
pull_request:
@@ -19,7 +16,7 @@ jobs:
1916
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2017
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2118
with:
22-
node-version: '22'
19+
node-version-file: package.json
2320
- run: |
2421
npm install
2522
npm run all
@@ -32,9 +29,13 @@ jobs:
3229
strategy:
3330
matrix:
3431
os: [ubuntu-latest, macos-latest, windows-latest]
32+
env:
33+
RUNNER_DEBUG: 1
3534
steps:
3635
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3736
- uses: ./
37+
with:
38+
version: 'latest'
3839
- name: Get the version
3940
run: vals version
4041
- uses: ./

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.github/**/*.yaml
2+
.github/**/*.md
23
dist/*

__fixtures__/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type * as core from '@actions/core'
22
import { jest } from '@jest/globals'
33

4+
export const addPath = jest.fn<typeof core.addPath>()
45
export const debug = jest.fn<typeof core.debug>()
56
export const error = jest.fn<typeof core.error>()
67
export const info = jest.fn<typeof core.info>()

__tests__/main.test.ts

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
* functions and objects. For example, the core module is mocked in this test,
66
* so that the actual '@actions/core' module is not imported.
77
*/
8+
9+
import fs from 'fs/promises'
10+
import os from 'os'
11+
import path from 'path'
12+
813
import { jest } from '@jest/globals'
914
import * as core from '../__fixtures__/core.js'
1015

16+
import { toolName, defaultVersion } from '../src/tool.js'
17+
1118
// Mocks should be declared before the module being tested is imported.
1219
jest.unstable_mockModule('@actions/core', () => core)
1320

@@ -16,26 +23,70 @@ jest.unstable_mockModule('@actions/core', () => core)
1623
const { run } = await import('../src/main.js')
1724

1825
describe('main.ts', () => {
19-
beforeEach(() => {
26+
const OLD_ENV = process.env
27+
28+
beforeEach(async () => {
2029
// Set the action's inputs as return values from core.getInput().
21-
core.getInput.mockImplementation(() => '500')
30+
core.getInput.mockImplementation(() => defaultVersion.replaceAll('v', ''))
31+
process.env = { ...OLD_ENV } // Make a copy
32+
33+
switch (os.type()) {
34+
case 'Linux':
35+
process.env.RUNNER_OS = 'Linux'
36+
break
37+
case 'Darwin':
38+
process.env.RUNNER_OS = 'macOS'
39+
break
40+
case 'Windows_NT':
41+
process.env.RUNNER_OS = 'Windows'
42+
break
43+
default:
44+
throw new Error(`Unsupported OS: ${os.type()}`)
45+
}
46+
47+
process.env.RUNNER_ARCH = 'X86_64'
48+
49+
process.env.RUNNER_TEMP = await fs.mkdtemp(
50+
path.join(os.tmpdir(), `${toolName}-runner-temp-`)
51+
)
52+
53+
process.env.RUNNER_TOOL_CACHE = await fs.mkdtemp(
54+
path.join(os.tmpdir(), `${toolName}-tool-cache-`)
55+
)
2256
})
2357

24-
afterEach(() => {
58+
afterEach(async () => {
59+
if (process.env.RUNNER_TOOL_CACHE) {
60+
await fs.rm(process.env.RUNNER_TOOL_CACHE, {
61+
recursive: true,
62+
force: true
63+
})
64+
}
65+
66+
if (process.env.RUNNER_TEMP) {
67+
await fs.rm(process.env.RUNNER_TEMP, {
68+
recursive: true,
69+
force: true
70+
})
71+
}
72+
2573
jest.resetAllMocks()
74+
process.env = OLD_ENV // Restore old environment
2675
})
2776

2877
it('Run main', async () => {
2978
await run()
3079

31-
/*
80+
// Verify that no errors were thrown.
81+
expect(core.setFailed).not.toHaveBeenCalled()
82+
3283
// Verify the time output was set.
3384
expect(core.setOutput).toHaveBeenNthCalledWith(
3485
1,
35-
'sops-path',
36-
// Simple regex to match a time string in the format HH:MM:SS.
37-
expect.stringMatching(/^sops/)
86+
'path',
87+
expect.stringMatching(
88+
new RegExp(`${toolName}[/\\\\]${defaultVersion.replaceAll('v', '')}`)
89+
)
3890
)
39-
*/
4091
})
4192
})

0 commit comments

Comments
 (0)