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

Attest release archives and publish to the BCR #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kormide
Copy link
Collaborator

@kormide kormide commented Feb 28, 2025

This updates the reusable release workflow to publish attestations and adds a new publish workflow for mirroring a release to the Bazel Central Registry.

The publish workflow can be set up to run automatically after a successful release run (configured in the calling repo), or manually. The manual option allows the publish to re-run from main, for the release tag, in case there was an error, for example, incorrect template files in .bcr.

I made some breaking changes to the release_prep.sh script inputs and outputs due to the need to identify the release archive for attesting. A release can upload many different artifacts and there wasn't surefire way to single out the archive. See an example release_prep.sh in one of my test fixtures.

@kormide kormide force-pushed the provenance branch 30 times, most recently from d070a63 to 7d0688f Compare March 4, 2025 00:47
@kormide kormide force-pushed the provenance branch 11 times, most recently from 8d0c137 to b06a4d9 Compare March 6, 2025 03:21
@kormide kormide changed the title feat: attest release artifacts Attest release archives and publish to the BCR Mar 6, 2025
@kormide kormide marked this pull request as ready for review March 6, 2025 03:24
# in the entry that we will publish later. This entry will be discarded.
- name: Create entry
id: create-entry
uses: bazel-contrib/publish-to-bcr@fa7d3c8ad241c2c0cde639eb2225be55816e9565
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: cut a release of the publish to bcr action and point to the version tag

Comment on lines -16 to -21
release_files:
required: true
description: |
Newline-delimited globs of paths to assets to upload for release.
See https://github.com/softprops/action-gh-release#inputs
type: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The files to upload to the release are now determined by the release_prep.sh script. The script is supplied with a pre-created directory defined in $ARTIFACTS_DIR to put all artifacts. The script also returns a JSON blob pointing out which artifact(s) are release archives so that we know what to attest.

A couple of alternative solutions are:

  • We keep release_files but also add attest_files.
  • We automatically attest all files under $ARTIFACTS_DIR, not just the release archives.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my opinion, I like giving all of the responsibility for the release to the release_prep.sh script, rather than partially the script and partially some inputs.

Comment on lines 27 to 44
The script will be provided with the following env vars:

ARTIFACTS_DIR: Path to a pre-created directory where all artifacts to be
uploaded to the GitHub release must be placed.

RELEASE_NOTES: Path to a pre-created file where release notes content should
be written.

The following arguments are passed to the script:

<tag_or_ref> The tag supplied as an input to this workflows, or ${{ github.ref_name }}.

The script must output a JSON blob with paths to release archives. The path can
be absolute or relative to the ARTIFACTS_DIR. For example:

{
"release_archives": ["my-ruleset-vX.Y.Z.tar.gz"]
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can understand this new API for release_prep being controversial because it will be a breaking change. I'm open to ideas to try to make it less breaking. The crux is that we need a way to identify release archives for the attestations later on in the workflow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I chose JSON output so that it's extensible in the future, for example, maybe we'll have a attest_artifacts property for users who wish to attest more files. GitHub runners have jq installed so parsing is easy.

@kormide
Copy link
Collaborator Author

kormide commented Mar 6, 2025

Please review @alexeagle, @loosebazooka, @meteorcloudy, @fweikert. I don't have the permissions to request a review on this repo.

@kormide kormide force-pushed the provenance branch 3 times, most recently from 9d454e1 to 8f808b4 Compare March 6, 2025 03:52
Comment on lines +67 to +72
- name: Checkout BCR
uses: actions/[email protected]
with:
repository: ${{ github.event.inputs.registry }}
token: ${{ secrets.GITHUB_TOKEN }}
path: bazel-central-registry
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: experiment with sparse checkouts

Comment on lines +90 to +96
# Create an initial entry so that we can attest the generated source.json and MODULE.bazel
# files. These are needed to solve a chicken and egg problem where the attestations are referenced
# by attestations.template.json entry file, which is included in the entry published later on.
# This entry will be discarded.
- name: Create entry
id: create-entry
uses: bazel-contrib/publish-to-bcr@fa7d3c8ad241c2c0cde639eb2225be55816e9565
Copy link
Collaborator Author

@kormide kormide Mar 6, 2025

Choose a reason for hiding this comment

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

I can see an argument for making a second action in publish-to-bcr that only outputs the attestations, since that's all we're creating the entry here for. But it's an internal implementation detail for now.

@kormide
Copy link
Collaborator Author

kormide commented Mar 6, 2025

I think we need a nice README.md documenting all of these reusable workflows. I can do a documentation pass after this lands.

Comment on lines +201 to +203
- name: Create Pull Request
id: create-pull-request
uses: peter-evans/create-pull-request@v7
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: verify that an existing PR can be updated on a second publish

Comment on lines +114 to +117
# Publish to BCR can run substitutions on an attestations.template.json file. Add a default
# template here and don't require it to exist in the module repo's .bcr templates folder.
- name: Create attestations template
working-directory: this/.bcr
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Although this is a long script and it's tempting to put it in a file, it's surprisingly difficult to try to reference a file in a reusable workflow. This is because it runs in the context of the calling workflow. GitHub does not provide any path with a checkout of the reusable workflow repository, and it does not provide the ref used. The only way to properly reference a file is to pass in the reusable workflow ref/tag as an input, then manually check it out at that ref and retrieve the file.

@alexeagle alexeagle self-requested a review March 6, 2025 16:18
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.

1 participant