Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Github Action for notation setup #5

Merged
merged 20 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Notation Action
# Notation Action
16 changes: 16 additions & 0 deletions setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: setup-gh
description: Setup Notation CLI on GitHub Action runners
branding:
icon: check-circle
color: blue
inputs:
version:
description: Version of Notation CLI to install
required: false
default: 1.0.0-rc.7
url:
description: URL of Notation CLI to install
required: false
runs:
using: node16
main: dist/index.js
2 changes: 2 additions & 0 deletions setup/dist/index.js

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

1 change: 1 addition & 0 deletions setup/dist/index.js.map

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

9 changes: 9 additions & 0 deletions setup/dist/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@vercel/ncc
MIT
Copyright 2018 ZEIT, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions setup/dist/sourcemap-register.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions setup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const path = require('path');
const core = require('@actions/core');
const tc = require('@actions/tool-cache');
const { getDownloadObject } = require('./lib/utils');
const fs = require('fs');
const mv = require('mv');
const { version } = require('os');
const execSync = require('child_process').execSync;

async function setup() {
try {
// Get version of tool to be installed
const version = core.getInput('version');

// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version);
console.log(download)
const pathToTarball = await tc.downloadTool(download.url);

// Extract the tarball/zipball onto host runner
const extract = download.url.endsWith('.zip') ? tc.extractZip : tc.extractTar;
const pathToCLI = await extract(pathToTarball);
fs.mkdirSync(pathToCLI + "/" + download.binPath, { recursive: true, })

const currentPath = path.join(pathToCLI, "notation")
const destinationPath = path.join(pathToCLI, "/", download.binPath, "/", "notation")
mv(currentPath, destinationPath, function (err) {
if (err) {
throw err
} else {
console.log("Successfully moved the Notation binary to bin.");
}
});
// Expose the tool by adding it to the PATH
core.addPath(path.join(pathToCLI, download.binPath));


} catch (e) {
core.setFailed(e);
}
}

module.exports = setup

if (require.main === module) {
setup();
}
32 changes: 32 additions & 0 deletions setup/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { setFailed } = require('@actions/core');
const os = require('os');
const path = require('path');
const execSync = require('child_process').execSync;
const semver = require('semver');
const core = require('@actions/core');
const arch = "amd64";

// os in [darwin, linux, win32...] (https://nodejs.org/api/os.html#os_os_platform)
// return value in [darwin, linux, windows]
function mapOS(os) {
const mappings = {
darwin: 'macOS',
win32: 'windows'
};
return mappings[os] || os;
}

function getDownloadObject(version) {
const platform = os.platform();
const filename = `notation_${version}_${mapOS(platform)}_${arch}`;
const extension = platform === 'win32' ? 'zip' : 'tar.gz';
const binPath = platform === 'win32' ? 'bin' : path.join(filename, 'bin');
const url = `https://github.com/notaryproject/notation/releases/download/v${version}/${filename}.${extension}`;
return {
url,
binPath,
filename
};
}

module.exports = { getDownloadObject }
Loading