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 composite action to add vendordeps and make a PR #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/add_vendordep/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 'Add Vendordep'
description: 'Adds a vendordep to the repository and creates a pull request the upstream repo'

inputs:
token:
description: 'Build Buddy API token'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: 'Build Buddy API token'
description: 'GitHub API token'

required: true
vendordep_file:
description: 'Path to the vendordep file to upload'
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be absolute (since it's used inside the vendor-json-repo directory)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

required: true
pr_title:
description: 'The contents used as the PR title when opening the pull request'
required: true
pr_branch:
description: 'The name of the branch to use when creating the pull request'
required: true
is_beta:
description: "If true, this will be added to the years beta files"
default: false
required: false


runs:
using: "composite"
steps:
- uses: actions/checkout@v4
with:
repository: 'wpilibsuite/vendor-json-repo'
fetch-depth: 0 # Fetch all history so we can use git diff
path: "vendor-json-repo"
ref: "main"

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Add vendordep
shell: bash
run: python add_vendordep.py --vendordep_file=$VENDORDEP_FILE --is_beta=$IS_BETA
working-directory: vendor-json-repo
env:
VENDORDEP_FILE: ${{ inputs.vendordep_file }}
IS_BETA: ${{ inputs.is_beta }}

- name: Debug
shell: bash
run: git --no-pager diff
working-directory: vendor-json-repo

- name: Create Gentool Pull Request
uses: peter-evans/create-pull-request@v6
with:
path: vendor-json-repo
base: main
branch: ${{ inputs.pr_branch }}
token: ${{ inputs.token }}
title: ${{ inputs.pr_title }}
Copy link

@Gold856 Gold856 Dec 19, 2024

Choose a reason for hiding this comment

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

Need to put push-to-fork here. I think just specifying ${{ github.repository_owner}}/vendor-json-repo as the value will work as long as all forks keep the vendor-json-repo name. Instructions should be modified to specify a fork is needed and for the repo name to be the same as this one.

Copy link
Member

Choose a reason for hiding this comment

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

I would just add that as an input and let the downstream user decide

5 changes: 5 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ py_binary(
visibility = ["//visibility:public"],
)

py_binary(
name = "add_vendordep",
srcs = ["add_vendordep.py"],
)

# Change this for local testing only.
cache_directory = None

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,28 @@ Pyunit tests are automatically auto generated run using the checker tool against

### Running the tests
To run the tests, simply run `bazel test //...`. Alternatively, you can run the `checker.py` tool in a standalone mode by running `bazel run //:checker -- <command line arguments from above>`

## Automatically creating pull requests
If your libraries CI creates a new vendordep.json file, you can use an action contained in this repository to automatically create a pull request to add your changes. In order for the action to work, you must define a secret with write access to be able to create the pull request.

Here is an example workflow:

```
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- uses: actions/checkout@v4

# Steps to package your vendordep file. It is recommended that you store the new version number in a variable so that it can be used later when creating your PR's title and branch name

- id: create_pull_request
uses: wpilibsuite/vendor-json-repo/.github/actions/add_vendordep@latest
with:
token: ${{ secrets.PUBLISH_VENDOR_JSON_TOKEN }}
vendordep_file: <path to vendordep file>
pr_title: "Automatically add <library name> version <version>"
pr_branch: "publish_<library name>_<version>"
is_beta: true
```
57 changes: 57 additions & 0 deletions add_vendordep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import json
import argparse
from pathlib import Path
import shutil


def add_vendordep(vendordep_filename, is_beta):
vendordep_contents = json.loads(vendordep_filename.read_bytes())
year = vendordep_contents['frcYear'] + "beta" if is_beta else ""

year_filename = Path(f"{year}.json")
year_contents = json.loads(year_filename.read_bytes())

metadata_filename = Path(f"{year}_metadata.json")
metadata_contents = json.loads(metadata_filename.read_bytes())

for metadata_lib in metadata_contents:
if metadata_lib["uuid"] == vendordep_contents["uuid"]:
break
else:
raise Exception("This appears to be a new library that does not have metadata associated with it. Can not automatically update")

vendordep_destination = Path(f"{year}/{vendordep_filename.name}")

year_contents.append(dict(
path=str(vendordep_destination),
name=metadata_lib["name"],
version=vendordep_contents["version"],
uuid=metadata_lib["uuid"],
description=metadata_lib["description"],
website=metadata_lib["website"],
))
Comment on lines +25 to +32
Copy link
Member

@rzblue rzblue Dec 19, 2024

Choose a reason for hiding this comment

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

YEAR.json is generated as an artifact automatically now, adding the json to the directory is all that's necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where does this happen? If that happens I feel like there should be a gen-is-the-same test or these files can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so it happens in generate_year_bundles, which only publishes to artifactory. The file in the root still has to be updated (either by hand or through a script) for the tests to pass.

I think either these files should be generated and checked, or removed. generate_year_bundles seems to enforce some of the checks the tests do so it might be redundant

Copy link
Contributor

Choose a reason for hiding this comment

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

They will be removed, but removing them will break beta 1 & 2 VS Code extensions.

Copy link
Member

Choose a reason for hiding this comment

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

We've already broken them. I'm working on removing all the obsolete stuff and documenting the new process


year_filename.write_text(json.dumps(year_contents, indent=2))
shutil.copy(vendordep_filename, vendordep_destination)

def main():
parser = argparse.ArgumentParser(
"Generates one or more vendordep repository bundles for publication"
Copy link
Member

Choose a reason for hiding this comment

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

needs changed

)
parser.add_argument(
"--vendordep_file",
type=Path
)
parser.add_argument(
"--is_beta",
type=bool
)
args = parser.parse_args()

add_vendordep(args.vendordep_file, args.is_beta)




if __name__ == "__main__":
main()
Loading