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

Add a GitHub Action for installing slsa-verifier. #246

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

kpk47
Copy link
Contributor

@kpk47 kpk47 commented Sep 2, 2022

This is a rewrite of #233 in Typescript.

@asraa @ianlewis @laurentsimon

@kpk47 kpk47 marked this pull request as ready for review September 2, 2022 01:50
Copy link
Contributor

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Left a few comment. I think this is the "allow installation of any version". Heard back from Ian whether he's OK with using the @v1.2.3 opption instead?

.github/workflows/test_install.yml Outdated Show resolved Hide resolved
actions/installer/dst/index.js Outdated Show resolved Hide resolved
actions/installer/src/index.ts Outdated Show resolved Hide resolved
@kpk47
Copy link
Contributor Author

kpk47 commented Sep 2, 2022

@laurentsimon I spoke with Ian about pinning by release tags, and he's fine with it. Unfortunately, I've written a bunch of versions of this action and decided that I like the version with a version input and an explicit LATEST_VERSION in the javascript. Here's my reasoning. LMK if you disagree.

Pros

  • Users can still pin to a release tag if they want. The version input is optional, and pinning to a release tag will install whichever version was latest at the time of release (i.e. @1.2.3 will install v1.2.3).
  • If we have an explicit LATEST_VERSION in the code, users can pin to a commit hash. GH's documentation on using public actions recommends pinning to a commit SHA rather than a release version or main, so I think it's important we support that use case.
  • It's easier to write the action if it takes the version as input. action_path and action_ref are not part of the subset of the GH context that's available to Javascript actions, so getting the version that way requires an ugly hack with a second (composite) action. I wrote that version and discarded it because my intuition is that it would be brittle.
  • It's easier to test the action if it takes the version as an input since we can use a matrix to cover all supported release versions. We cannot parse the version from a local action (it's always main at whatever commit you have checked out), so we'd need to use a second repo for running tests. I don't think it's worth the hassle.
  • After looking through the GHA Marketplace, I realized that it would be very unusual if we only allowed choosing the installed version by pinning the action to a release tag. Every other *-setup action I found either supported taking the version as an input or only supported installing the latest release. I think that being unusual in this way would be helpful for adoption.

Cons

  • We have to keep the LATEST_VERSION constant up to date, which most likely means adding an extra step to our release process.

@laurentsimon
Copy link
Contributor

laurentsimon commented Sep 2, 2022

@laurentsimon I spoke with Ian about pinning by release tags, and he's fine with it. Unfortunately, I've written a bunch of versions of this action and decided that I like the version with a version input and an explicit LATEST_VERSION in the javascript. Here's my reasoning. LMK if you disagree.

Pros

  • Users can still pin to a release tag if they want. The version input is optional, and pinning to a release tag will install whichever version was latest at the time of release (i.e. @1.2.3 will install v1.2.3).
  • If we have an explicit LATEST_VERSION in the code, users can pin to a commit hash. GH's documentation on using public actions recommends pinning to a commit SHA rather than a release version or main, so I think it's important we support that use case.

We can support this pinning by hash by getting the hash from the GITHUB_ACTION_PATH env variable, iterating over releases and finding the one that corresponds to the hash. Note that it would be fine to have a first version that only supports tag pins. Not a problem.

  • It's easier to write the action if it takes the version as input. action_path and action_ref are not part of the subset of the GH context that's available to Javascript actions, so getting the version that way requires an ugly hack with a second (composite) action. I wrote that version and discarded it because my intuition is that it would be brittle.

action_path is accessible thru GITHUB_ACTION_PATH env variable, and it contains the ref, which is either a tag or as hash.

  • It's easier to test the action if it takes the version as an input since we can use a matrix to cover all supported release versions. We cannot parse the version from a local action (it's always main at whatever commit you have checked out), so we'd need to use a second repo for running tests. I don't think it's worth the hassle.

We can use an API to list the version, and dynamically generate the matrix, as in https://michaelheap.com/dynamic-matrix-generation-github-actions/.

  • After looking through the GHA Marketplace, I realized that it would be very unusual if we only allowed choosing the installed version by pinning the action to a release tag. Every other *-setup action I found either supported taking the version as an input or only supported installing the latest release. I think that being unusual in this way would be helpful for adoption.

That's the main argument against.

Cons

  • We have to keep the LATEST_VERSION constant up to date, which most likely means adding an extra step to our release process.

Let's enjoy the week-end. I know re-writing so many times is frustrating. Let's sync next week.
Thanks again for the hard work you've put into this. Maybe we've been a bit unlucky with the choice of the first PR :/

Copy link
Contributor

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Just added a nit to rename files for pre-submit, and we're good to merge

.github/workflows/test_install.yml Outdated Show resolved Hide resolved
Copy link
Member

@ianlewis ianlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

.github/workflows/pre-submit.yml Outdated Show resolved Hide resolved
.github/workflows/pre-submit.yml Outdated Show resolved Hide resolved
.github/workflows/pre-submit.yml Outdated Show resolved Hide resolved
actions/installer/README.md Outdated Show resolved Hide resolved
actions/installer/README.md Outdated Show resolved Hide resolved
actions/installer/README.md Outdated Show resolved Hide resolved
actions/installer/spec/index.test.ts Show resolved Hide resolved
actions/installer/src/index.ts Outdated Show resolved Hide resolved
actions/installer/src/index.ts Outdated Show resolved Hide resolved
actions/installer/src/index.ts Show resolved Hide resolved
Copy link
Contributor

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we'd use the GITHUB_ACTION_PATH to determine the version to download?

@kpk47
Copy link
Contributor Author

kpk47 commented Sep 8, 2022

@laurentsimon
Copy link
Contributor

@laurentsimon GITHUB_ACTION_PATH is only available to composite actions (https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables).

ouch, all these strange corner cases. Good find!
One hack is to declare a composite action and have a single step that calls node code.js. Does this work?

Note: GH are working on better APIs for Actions / re-usable workflows to determine their identity / ref, so later we should be able to use it.

@kpk47
Copy link
Contributor Author

kpk47 commented Sep 15, 2022

Okay, I think I've address all of your comments. PTAL and then I think we're ready to merge.

@laurentsimon
Copy link
Contributor

Please re-base

## Usage

To install the latest version, use:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this. We don't want to encourage this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// If actionRef is a commit SHA, then find the associated version number.
const shaRe = /^[a-f\d]{40}$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I copied it from you (slsa-framework/slsa-github-generator#86). 😅

shell: bash
run: npm ci

- name: Run build and tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to remove the test in the main action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.github/workflows/pre-submit.actions.yml Show resolved Hide resolved
@ianlewis
Copy link
Member

LGTM, pending doc changes that @laurentsimon commented on, and merging the conflicting pre-submit.yml changes.

@kpk47
Copy link
Contributor Author

kpk47 commented Sep 16, 2022

I think I've fixed the merge conflicts, but I can't get GitHub to recognize it. I dropped the changes in pre-submit.yml in favor of a straight rename, so I'm not sure what else I can do.

@laurentsimon
Copy link
Contributor

yeah things get weird when re-basing and files that are deleted have some updates. Have you tried git rm the pre-submit.yml to see if it helps?

@kpk47
Copy link
Contributor Author

kpk47 commented Sep 19, 2022

Okay, I think I got it. For posterity, the fix was re-adding pre-submit.yml, merging in changes from main, removing pre-submit.cli.yml, and then re-doing the name change from pre-submit.yml to pre-submit.cli.yml.


See https://github.com/slsa-framework/slsa-verifier/releases for the list of available `slsa-verifier` releases.

For a full example workflow, see [../../.github/workflows/test_installer.yml](https://github.com/slsa-framework/slsa-verifier/.github/workflows/test_installer.yml).
Copy link
Contributor

@laurentsimon laurentsimon Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think think this file exists anymore, does it? Let's remove this line. You can send a PR to add an example to this README later, including a link to it from the main README.

@laurentsimon laurentsimon enabled auto-merge (squash) September 19, 2022 22:12
auto-merge was automatically disabled September 19, 2022 22:19

Head branch was pushed to by a user without write access

@laurentsimon laurentsimon enabled auto-merge (squash) September 19, 2022 22:37
auto-merge was automatically disabled September 22, 2022 16:58

Head branch was pushed to by a user without write access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants