-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (31 loc) · 1011 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const path = require("path");
const core = require("@actions/core");
const github = require("@actions/github");
const fs = require('fs')
try {
const finalPackagePath = path.resolve(
process.env.GITHUB_WORKSPACE,
core.getInput("versionFilePath")
);
if(!fs.existsSync(finalPackagePath)){
throw new Error(`Version file path not found: ${finalPackagePath}`)
}
const packageInfo = require(finalPackagePath);
if (github.context.payload.ref) {
const ref = github.context.payload.ref;
const refVersionParts = ref.split(/\//gi);
const refVersion = refVersionParts[refVersionParts.length - 1];
if (packageInfo.version.toLowerCase() !== refVersion.toLowerCase()) {
core.setFailed(
`Package version is ${packageInfo.version}, tag version is ${refVersion}`
);
} else {
process.exit(0);
}
} else {
core.setFailed("This action can only be called from a tagged ref");
}
} catch (err) {
console.error(err);
core.setFailed(err.message);
}