Skip to content

Commit

Permalink
Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed May 27, 2022
1 parent 646f96a commit d64f4a6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
lib
/.idea
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

61 changes: 30 additions & 31 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,67 +37,67 @@ async function createCertificatePfx() {

async function addCertificateToStore(){
try {
const password : string= core.getInput('password');
if (password == ''){
const password: string = core.getInput('password');
if (password == '') {
console.log("Password is required to add pfx certificate to store");
return false;
return false;
}
var command = `certutil -f -p ${password} -importpfx ${certificateFileName}`
console.log("Adding cert to store command: " + command);
const command = `certutil -f -p ${password} -importpfx ${certificateFileName}`
console.log(`Adding cert to store command: ${command}`);
const { stdout } = await asyncExec(command);
console.log(stdout);
return true;
} catch(err) {
console.log(err.stdout);
console.log(err.stderr);
} catch (err) {
console.log(err);
return false;
}
}

async function signWithSigntool(fileName: string) {
try {
// var command = `"${signtool}" sign /sm /tr ${timestampUrl} /sha1 "1d7ec06212fdeae92f8d3010ea422ecff2619f5d" /n "DanaWoo" ${fileName}`
var vitalParameterIncluded = false;
var timestampUrl : string = core.getInput('timestampUrl');
let vitalParameterIncluded = false;
let timestampUrl: string = core.getInput('timestampUrl');
if (timestampUrl === '') {
timestampUrl = 'http://timestamp.digicert.com'; // 'http://timestamp.digicert.com';//
}
var command = `"${signtool}" sign /sm /tr ${timestampUrl}`
const sha1 : string= core.getInput('certificatesha1');
if (sha1 != ''){
let command = `"${signtool}" sign /sm /tr ${timestampUrl}`
const sha1: string = core.getInput('certificatesha1');
if (sha1 != '') {
command = command + ` /sha1 "${sha1}"`
vitalParameterIncluded = true;
vitalParameterIncluded = true;
}
const name : string= core.getInput('certificatename');
if (name != ''){
vitalParameterIncluded = true;
const name : string = core.getInput('certificatename');
if (name != '') {
vitalParameterIncluded = true;
command = command + ` /n "${name}"`
}
if (!vitalParameterIncluded){
console.log("You need to include a NAME or a SHA1 Hash for the certificate to sign with.")
if (!vitalParameterIncluded) {
console.log('You need to include a NAME or a SHA1 Hash for the certificate to sign with.')
}
command = command + ` ${fileName}`;
console.log("Signing command: " + command);
command = `${command} ${fileName}`;
console.log(`Signing command: ${command}`);
const { stdout } = await asyncExec(command);
console.log(stdout);
return true;
} catch(err) {
console.log(err.stdout);
console.log(err.stderr);
console.log(err);
return false;
}
}

async function trySignFile(fileName: string) {
console.log(`Signing ${fileName}.`);
const extension = path.extname(fileName);
for (let i=0; i< 10; i++) {
for (let i = 0; i < 3; i++) {
await sleep(i);
if (signtoolFileExtensions.includes(extension)) {
if (await signWithSigntool(fileName))
if (await signWithSigntool(fileName)) {
return;
}
}
}

throw `Failed to sign '${fileName}'.`;
}

Expand All @@ -108,10 +108,10 @@ async function* getFiles(folder: string, recursive: boolean): any {
const stat = await fs.stat(fullPath);
if (stat.isFile()) {
const extension = path.extname(file);
if (signtoolFileExtensions.includes(extension) || extension == '.nupkg')
if (signtoolFileExtensions.includes(extension) || extension == '.nupkg') {
yield fullPath;
}
else if (stat.isDirectory() && recursive) {
}
} else if (stat.isDirectory() && recursive) {
yield* getFiles(fullPath, recursive);
}
}
Expand All @@ -129,11 +129,10 @@ async function run() {
try {
if (await createCertificatePfx())
{
if (await addCertificateToStore())
if (await addCertificateToStore())
await signFiles();
}
}
catch (err) {
} catch (err) {
core.setFailed(`Action failed with error: ${err}`);
}
}
Expand Down
42 changes: 29 additions & 13 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-sign-action",
"version": "1.0.0",
"version": "2.0.0",
"description": "Sign files with a code signing certificate.",
"main": "index.js",
"scripts": {
Expand All @@ -18,11 +18,11 @@
},
"homepage": "https://github.com/DanaBear/code-sign-action#readme",
"dependencies": {
"@actions/core": "^1.2.0"
"@actions/core": "^1.8.2"
},
"devDependencies": {
"@types/node": "^12.11.1",
"@zeit/ncc": "^0.20.5",
"typescript": "^3.6.4"
"@types/node": "^17.0.35",
"@zeit/ncc": "^0.22.3",
"typescript": "^4.7.2"
}
}

0 comments on commit d64f4a6

Please sign in to comment.