Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/build-and-test.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(core, 'setOutput').mockImplementation();

expect(await run.run()).toBeUndefined();
expect(core.getInput).toBeCalledWith('version', { 'required': true });
expect(core.addPath).toBeCalledWith('pathToCachedTool');
expect(core.setOutput).toBeCalledWith('cuectl-path', path.join('pathToCachedTool', 'cue'));
expect(core.getInput).toHaveBeenCalledWith('version', { 'required': true });
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool');
expect(core.setOutput).toHaveBeenCalledWith('cuectl-path', path.join('pathToCachedTool', 'cue'));
});

test('getExecutableExtension() must return .exe file extension when os equals Windows', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');

expect(run.getExecutableExtension()).toBe('.exe');
expect(os.type).toBeCalled();
expect(os.type).toHaveBeenCalled();
});

test('getExecutableExtension() must return an empty string for non-windows OS', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin');

expect(run.getExecutableExtension()).toBe('');
expect(os.type).toBeCalled();
expect(os.type).toHaveBeenCalled();
});

test.each([
Expand All @@ -58,7 +58,7 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);

expect(run.getCuectlOSArchitecture()).toBe(cuectlVersion);
expect(os.arch).toBeCalled();
expect(os.arch).toHaveBeenCalled();
});

test.each([
Expand All @@ -69,7 +69,7 @@ describe('Testing all functions in run file.', () => {
const cuectlLinuxUrl = util.format('https://github.com/cue-lang/cue/releases/download/v0.4.0/cue_v0.4.0_linux_%s.tar.gz', arch);

expect(run.getCuectlDownloadURL('v0.4.0', arch)).toBe(cuectlLinuxUrl);
expect(os.type).toBeCalled();
expect(os.type).toHaveBeenCalled();
});

test.each([
Expand All @@ -80,7 +80,7 @@ describe('Testing all functions in run file.', () => {
const cuectlDarwinUrl = util.format('https://github.com/cue-lang/cue/releases/download/v0.4.0/cue_v0.4.0_darwin_%s.tar.gz', arch);

expect(run.getCuectlDownloadURL('v0.4.0', arch)).toBe(cuectlDarwinUrl);
expect(os.type).toBeCalled();
expect(os.type).toHaveBeenCalled();
});

test.each([
Expand All @@ -90,7 +90,7 @@ describe('Testing all functions in run file.', () => {
const cuectlWindowsUrl = util.format('https://github.com/cue-lang/cue/releases/download/v0.4.0/cue_v0.4.0_windows_%s.zip', arch);

expect(run.getCuectlDownloadURL('v0.4.0', arch)).toBe(cuectlWindowsUrl);
expect(os.type).toBeCalled();
expect(os.type).toHaveBeenCalled();
});

test('downloadCuectl() must download cuectl tarball, add it to github actions tool cache and return the path to extracted dir', async () => {
Expand All @@ -103,11 +103,11 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});

expect(await run.downloadCuectl('v0.4.0')).toBe(path.join('pathToCachedTool', 'cue'));
expect(toolCache.find).toBeCalledWith('cue', 'v0.4.0');
expect(toolCache.downloadTool).toBeCalled();
expect(toolCache.cacheDir).toBeCalled();
expect(os.type).toBeCalled();
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedTool', 'cue'), '777');
expect(toolCache.find).toHaveBeenCalledWith('cue', 'v0.4.0');
expect(toolCache.downloadTool).toHaveBeenCalled();
expect(toolCache.cacheDir).toHaveBeenCalled();
expect(os.type).toHaveBeenCalled();
expect(fs.chmodSync).toHaveBeenCalledWith(path.join('pathToCachedTool', 'cue'), '777');
});

test('downloadCuectl() must download cuectl zip archive, add it to github actions tool cache and return the path to extracted dir', async () => {
Expand All @@ -120,11 +120,11 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});

expect(await run.downloadCuectl('v0.4.0')).toBe(path.join('pathToCachedTool', 'cue.exe'));
expect(toolCache.find).toBeCalledWith('cue', 'v0.4.0');
expect(toolCache.downloadTool).toBeCalled();
expect(toolCache.cacheDir).toBeCalled();
expect(os.type).toBeCalled();
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedTool', 'cue.exe'), '777');
expect(toolCache.find).toHaveBeenCalledWith('cue', 'v0.4.0');
expect(toolCache.downloadTool).toHaveBeenCalled();
expect(toolCache.cacheDir).toHaveBeenCalled();
expect(os.type).toHaveBeenCalled();
expect(fs.chmodSync).toHaveBeenCalledWith(path.join('pathToCachedTool', 'cue.exe'), '777');
});

test('getLatestCuectlVersion() must download latest version file, read version and return it', async () => {
Expand All @@ -133,7 +133,7 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(fs, 'readFileSync').mockReturnValue(response);

expect(await run.getLatestCuectlVersion()).toBe('v0.5.0');
expect(toolCache.downloadTool).toBeCalled();
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');
expect(toolCache.downloadTool).toHaveBeenCalled();
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8');
});
})
4 changes: 2 additions & 2 deletions action.cue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package action

import "json.schemastore.org/github"
import "cue.dev/x/githubactions"

action: github.#Action & {
action: githubactions.#Action & {
name: "Setup CUE environment"
description: "Setup a CUE environment and add it to the PATH."
inputs: version: {
Expand Down
6 changes: 3 additions & 3 deletions action.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 1 addition & 56 deletions ci_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,22 @@ package action

import (
"encoding/yaml"
"strings"
"path"
"tool/http"
"tool/file"
"tool/exec"
)

_goos: *"unix" | string @tag(os,var=os)

#repoRoot: exec.Run & {
cmd: "git rev-parse --show-toplevel"
stdout: string
}

// vendorgithubschema "vendors" 'cue import'-ed versions of the GitHub
// action and workflow schemas into cue.mod/pkg
//
// Under the proposal for CUE packagemanagement, this command is
// redundant.
command: vendorgithubschema: {
repoRoot: #repoRoot

getActionJSONSchema: http.Get & {
// Tip link for humans:
// https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-action.json
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/01e00802b38350cb7ec257b11c456639a5cd0acf/src/schemas/json/github-action.json"
}

importActionJSONSchema: exec.Run & {
stdin: getActionJSONSchema.response.body
cmd: "cue import -f -p github -l #Action: jsonschema: - -o -"
stdout: string
}

vendorGitHubActionSchema: file.Create & {
_path: path.FromSlash("cue.mod/pkg/json.schemastore.org/github/github-action.cue", "unix")
filename: path.Join([strings.TrimSpace(repoRoot.stdout), _path], _goos)
contents: importActionJSONSchema.stdout
}

getWorkflowJSONSchema: http.Get & {
// Tip link for humans:
// https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/6fe4707b9d1c5d45cfc8d5b6d56968e65d2bdc38/src/schemas/json/github-workflow.json"
}

importWorkflowJSONSchema: exec.Run & {
stdin: getWorkflowJSONSchema.response.body
cmd: "cue import -f -p github -l #Workflow: jsonschema: - -o -"
stdout: string
}

vendorGitHubWorkflowSchema: file.Create & {
_path: path.FromSlash("cue.mod/pkg/json.schemastore.org/github/github-workflow.cue", "unix")
filename: path.Join([strings.TrimSpace(repoRoot.stdout), _path], _goos)
contents: importWorkflowJSONSchema.stdout
}
}

// genworkflows exports workflow configurations to .yml files.
//
// When the as-yet-unpublished embeding example is implemented,
// this command will become superfluous and could be replaced
// by a cue export call.
command: genworkflows: {
repoRoot: #repoRoot

for _, w in workflows {
"\(w.filename)": file.Create & {
_path: path.FromSlash(".github/workflows", "unix")
filename: path.Join([strings.TrimSpace(repoRoot.stdout), _path, w.filename], _goos)
filename: path.Join([_path, w.filename], _goos)
contents: """
# Generated by cue cmd genworkflows; do not edit

Expand Down
8 changes: 8 additions & 0 deletions cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
module: "github.com/cue-lang/setup-cue"
language: {
version: "v0.9.0"
}
deps: {
"cue.dev/x/githubactions@v0": {
v: "v0.4.0"
}
}
Loading