Skip to content

Commit 1461022

Browse files
committed
cleanup & fixes for func action
1 parent e9f9397 commit 1461022

304 files changed

Lines changed: 85 additions & 395360 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-action.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: test-action
2-
on: [pull_request,workflow_dispatch]
2+
on: [pull_request, workflow_dispatch]
33

44
jobs:
5-
func:
5+
test:
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: functions-dev/action@main
8+
- uses: actions/checkout@v4
9+
- uses: ./
10+
- run: func version

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Func Action'
2-
description: 'This action does custom stuff for it is custom'
2+
description: 'Downloads and sets up the Knative func CLI'
33
inputs:
44
name:
55
description: '(optional) Name of the Function binary. It will be available in the runner under this name(defaults to "func")'

index.js

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const core = require('@actions/core');
2-
const exec = require('@actions/exec')
3-
const path = require('path')
2+
const exec = require('@actions/exec');
3+
const path = require('path');
44
const fs = require('fs');
55

6+
// Static version - update manually when new func releases are available
7+
const DEFAULT_FUNC_VERSION = 'knative-v1.20.1';
68

7-
// change this accordingly
8-
const DEFAULT_FUNC_VERSION = 'knative-v1.16.1'
9-
10-
// detect os system in Github Actions and determine binary name
119
function getOsBinName() {
1210
const runnerOS = process.env.RUNNER_OS;
1311
const runnerArch = process.env.RUNNER_ARCH;
@@ -33,14 +31,14 @@ function getOsBinName() {
3331
// to make it correct if possible.
3432
// Ex.: '1.16' or 'v1.16' will return 'v1.16.0'
3533
function smartVersionUpdate(version){
36-
versionRegex = /^(?<knprefix>knative-)?(?<prefix>v?)(?<major>\d+)\.(?<minor>\d+)(.(?<patch>\d+))?$/;
34+
const versionRegex = /^(?<knprefix>knative-)?(?<prefix>v?)(?<major>\d+)\.(?<minor>\d+)(.(?<patch>\d+))?$/;
3735
let match = version.match(versionRegex);
38-
if (match){
39-
if (match.groups.knprefix == undefined){
36+
if (match) {
37+
if (match.groups.knprefix === undefined) {
4038
match.groups.knprefix = "";
4139
}
4240
const prefix = 'v';
43-
if (match.groups.patch == undefined) {
41+
if (match.groups.patch === undefined) {
4442
match.groups.patch = 0;
4543
}
4644
return `${match.groups.knprefix}${prefix}${match.groups.major}.${match.groups.minor}.${match.groups.patch}`;
@@ -50,74 +48,51 @@ function smartVersionUpdate(version){
5048
return undefined;
5149
}
5250

53-
/**
54-
* @param {string} url - Full url to be curled
55-
* @param {string} binPath - Full target path of the binary
56-
*/
57-
// download func, set as executable
58-
async function cmdConstructAndRun(url,binPath){
51+
async function cmdConstructAndRun(url, binPath) {
5952
const cmd = `curl -L -o "${binPath}" "${url}"`;
6053
await exec.exec(cmd);
6154

62-
//check if downloaded successfully
63-
if (!fs.existsSync(binPath)){
55+
if (!fs.existsSync(binPath)) {
6456
core.setFailed("Download failed, couldn't find the binary on disk");
57+
return;
6558
}
6659

67-
await exec.exec(`chmod +x ${binPath}`);
60+
if (process.env.RUNNER_OS !== 'Windows') {
61+
await exec.exec(`chmod +x ${binPath}`);
62+
}
6863
}
6964

70-
/**
71-
* @param {string} binPath - full path to Func binary
72-
* */
73-
async function addBinToPath(binPath){
74-
dir = path.dirname(binPath)
75-
// Write to $GITHUB_PATH, making it available for subsequent steps
65+
async function addBinToPath(binPath) {
66+
const dir = path.dirname(binPath);
7667
fs.appendFileSync(process.env.GITHUB_PATH, `\n${dir}`);
7768

78-
// add only if its not in PATH yet
79-
if (!process.env.PATH.includes(dir)){
69+
if (!process.env.PATH.includes(dir)) {
8070
process.env.PATH = process.env.PATH + path.delimiter + dir;
81-
core.info(`dir ${dir} added to $PATH`);
71+
core.info(`${dir} added to PATH`);
8272
}
83-
}
73+
}
8474

85-
// -------------------------------------------------------------------------- \\
86-
async function run(){
75+
async function run() {
8776
try {
88-
89-
// Fetch value of inputs specified in action.yml or use defaults
90-
91-
// osBin refers to the exact name match of an existing binary available to
92-
// download
9377
const osBin = core.getInput('binary') || getOsBinName();
94-
if (osBin == "unknown"){
78+
if (osBin === "unknown") {
9579
core.setFailed("Invalid os binary determination, try setting it specifically using 'binary'");
80+
return;
9681
}
97-
// version to be downloaded
98-
let version = core.getInput('version') || DEFAULT_FUNC_VERSION
99-
// destination is a directory where to download the Func
82+
83+
let version = core.getInput('version') || DEFAULT_FUNC_VERSION;
10084
const destination = core.getInput('destination') || process.cwd();
101-
// bin refers to the name of the binary (Func) that will be downloaded (this
102-
// is what it will be called)
10385
const bin = core.getInput('name') || 'func';
10486

10587
version = smartVersionUpdate(version);
10688

107-
var url = `https://github.com/knative/func/releases/download/${version}/${osBin}`;
108-
console.log(`URL: ${url}`);
109-
110-
fullPathBin = path.resolve(destination,bin);
89+
const url = `https://github.com/knative/func/releases/download/${version}/${osBin}`;
90+
core.info(`URL: ${url}`);
11191

112-
// download Func
113-
await cmdConstructAndRun(url,fullPathBin);
92+
const fullPathBin = path.resolve(destination, bin);
11493

115-
// add final binary to PATH (directory where the bin is ) and add it to
116-
// GITHUB_PATH so it can be used bo subsequent 'runs'
94+
await cmdConstructAndRun(url, fullPathBin);
11795
await addBinToPath(fullPathBin);
118-
119-
await exec.exec("ls -la")
120-
// run 'func version' as a test
12196
await exec.exec(`${bin} version`);
12297

12398
} catch (error) {

node_modules/.package-lock.json

Lines changed: 4 additions & 207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)