Skip to content

Commit 37cf8fd

Browse files
authored
Fix installer: Add arguments to actions/checkout so that it checks ou… (#319)
* Fix installer: Add arguments to actions/checkout so that it checks out slsa-framework/slsa-verifier instead of the repo using the Action. Signed-off-by: kpk47 <[email protected]> * Switch to JS action * rebuild TS Signed-off-by: kpk47 <[email protected]>
1 parent 27597fe commit 37cf8fd

File tree

6 files changed

+39
-57
lines changed

6 files changed

+39
-57
lines changed

actions/installer/action.yml

+6-28
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,10 @@ description: 'Installs SLSA verifier and adds it to your PATH'
1717
branding:
1818
icon: 'package'
1919
color: 'blue'
20+
inputs:
21+
github-token:
22+
description: 'GitHub token'
23+
required: true
2024
runs:
21-
using: 'composite'
22-
steps:
23-
- name: Checkout
24-
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
25-
26-
- name: Setup Node.js 16
27-
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # tag=v3.5.0
28-
with:
29-
node-version: 16
30-
31-
- name: Install dependencies
32-
working-directory: actions/installer
33-
shell: bash
34-
run: npm ci
35-
36-
- name: Run build
37-
working-directory: actions/installer
38-
shell: bash
39-
run: npm run build
40-
41-
- name: Run installer
42-
env:
43-
ACTION_REF: "${{ github.action_ref }}"
44-
TOKEN: "${{ github.token }}"
45-
REPOSITORY: "${{ github.repository }}"
46-
working-directory: actions/installer/dist
47-
shell: bash
48-
run: nodejs index.js
25+
using: 'node16'
26+
main: 'dist/index.js'

actions/installer/dist/index.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,15 @@ function getVerifierVersion(actionRef) {
8181
// If actionRef is a commit SHA, then find the associated version number.
8282
const shaRe = /^[a-f\d]{40}$/;
8383
if (shaRe.test(actionRef)) {
84-
const octokit = github.getOctokit(process.env.TOKEN || "");
85-
const { data: releases } = yield octokit.request("GET /repos/{repository}/releases", {
86-
repository: process.env.REPOSITORY,
84+
const octokit = github.getOctokit(core.getInput("github-token"));
85+
const { data: tags } = yield octokit.request("GET /repos/{owner}/{repository}/tags", {
86+
owner: "slsa-framework",
87+
repository: "slsa-verifier",
8788
});
88-
for (const release of releases) {
89-
const { data: commit } = yield octokit.request("GET /reps/{repository}/git/ref/tags/{tagName}", {
90-
repository: process.env.REPOSITORY,
91-
tagName: release.tag_name,
92-
});
93-
const commitSha = commit.object.sha;
89+
for (const tag of tags) {
90+
const commitSha = tag.commit.sha;
9491
if (commitSha === actionRef) {
95-
return release.tag_name;
92+
return tag.name;
9693
}
9794
}
9895
}
@@ -123,7 +120,7 @@ function cleanup() {
123120
function run() {
124121
return __awaiter(this, void 0, void 0, function* () {
125122
// Get requested verifier version and validate
126-
const actionRef = process.env.ACTION_REF || "";
123+
const actionRef = process.env.GITHUB_ACTION_REF || "";
127124
let version;
128125
try {
129126
version = yield getVerifierVersion(actionRef);

actions/installer/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/installer/package-lock.json

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/installer/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
"package": "ncc build --source-map",
1212
"lint": "eslint src/**/*.ts",
1313
"build": "npm run compile && npm run package",
14+
"start": "node lib/index.js",
1415
"all": "npm run compile && npm run format && npm run lint && npm run test && npm run package"
1516
},
1617
"dependencies": {
1718
"@actions/core": "^1.9.1",
1819
"@actions/exec": "^1.1.1",
1920
"@actions/github": "^5.0.3",
2021
"@actions/io": "^1.1.2",
21-
"@actions/tool-cache": "^2.0.1"
22+
"@actions/tool-cache": "^2.0.1",
23+
"nodejs": "^0.0.0"
2224
},
2325
"devDependencies": {
2426
"@types/jasmine": "4.3.0",

actions/installer/src/index.ts

+9-15
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,18 @@ export async function getVerifierVersion(actionRef: string): Promise<string> {
4343
// If actionRef is a commit SHA, then find the associated version number.
4444
const shaRe = /^[a-f\d]{40}$/;
4545
if (shaRe.test(actionRef)) {
46-
const octokit = github.getOctokit(process.env.TOKEN || "");
47-
const { data: releases } = await octokit.request(
48-
"GET /repos/{repository}/releases",
46+
const octokit = github.getOctokit(core.getInput("github-token"));
47+
const { data: tags } = await octokit.request(
48+
"GET /repos/{owner}/{repository}/tags",
4949
{
50-
repository: process.env.REPOSITORY,
50+
owner: "slsa-framework",
51+
repository: "slsa-verifier",
5152
}
5253
);
53-
for (const release of releases) {
54-
const { data: commit } = await octokit.request(
55-
"GET /reps/{repository}/git/ref/tags/{tagName}",
56-
{
57-
repository: process.env.REPOSITORY,
58-
tagName: release.tag_name,
59-
}
60-
);
61-
const commitSha = commit.object.sha;
54+
for (const tag of tags) {
55+
const commitSha = tag.commit.sha;
6256
if (commitSha === actionRef) {
63-
return release.tag_name;
57+
return tag.name;
6458
}
6559
}
6660
}
@@ -94,7 +88,7 @@ async function cleanup(): Promise<void> {
9488

9589
async function run(): Promise<void> {
9690
// Get requested verifier version and validate
97-
const actionRef = process.env.ACTION_REF || "";
91+
const actionRef = process.env.GITHUB_ACTION_REF || "";
9892
let version: string;
9993
try {
10094
version = await getVerifierVersion(actionRef);

0 commit comments

Comments
 (0)