Skip to content

Commit

Permalink
Create Initial Workflows (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
legoguy1000 authored Jan 9, 2025
1 parent 01186ed commit ab0dcbd
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/frc-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This is a basic workflow to help you get started with Actions

name: FRC CI Checks

# Controls when the action will run.
on:
workflow_call:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4 # v2 minimum required
- name: Run check style
uses: dbelyaev/action-checkstyle@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: 'github-check'
fail_on_error: true
filter_mode: nofilter
level: error
checkstyle_config: checks.xml
spell_check:
name: Spell Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4 # v2 minimum required
- name: Run Spell Check
uses: codespell-project/actions-codespell@master
with:
check_filenames: true
merge_conflict_job:
runs-on: ubuntu-latest
name: Find merge conflicts
steps:
# Checkout the source code so there are some files to look at.
- uses: actions/checkout@v4
# Run the actual merge conflict finder
- name: Merge Conflict finder
uses: olivernybroe/[email protected]
build-javadoc:
name: Build Javadocs
# The type of runner that the job will run on
runs-on: ubuntu-latest
# This grabs the WPILib docker container
container: wpilib/roborio-cross-ubuntu:2025-24.04
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Runs a single command using the runners shell
- name: Create Javadocs
run: ./gradlew javadoc
- uses: actions/upload-artifact@v4
with:
name: javadocs
path: './build/docs/javadoc'
deploy-javadoc:
if: success() && github.ref_name == github.event.repository.default_branch
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
name: Deploy Javadocs
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: build-javadoc
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/download-artifact@v4
with:
name: javadocs
path: './build/docs/javadoc'
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to Github Pages
id: deployment
uses: actions/deploy-pages@v4
build:
name: Build
# The type of runner that the job will run on
runs-on: ubuntu-latest
# This grabs the WPILib docker container
container: wpilib/roborio-cross-ubuntu:2025-24.04
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Runs a single command using the runners shell
- name: Compile and run tests on robot code
run: ./gradlew build
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push
push:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
REGISTRY: ghcr.io
permissions:
packages: write
contents: read
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-container:
name: Build
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: "./vendor-update"
file: "./vendor-update/Dockerfile"
push: true
tags: ${{ env.REGISTRY }}/frc5572/worflows/vendor-update:${{ github.ref_name }}
31 changes: 31 additions & 0 deletions .github/workflows/update-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Check for Vendor Dependencies

# Controls when the action will run.
on:
workflow_call:
inputs:
base_branch:
required: true
type: string
default: main
version:
required: true
type: string
default: main

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
vendor-update-check:
name: Linting
runs-on: ubuntu-latest
container: ghcr.io/Frc5572/Worflows/vendor-update:${{ inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Update check
run: python /app/vendor-update.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: ${{ inputs.base_branch }}
REPO_PATH: ${{ github.repository }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
.env
7 changes: 7 additions & 0 deletions vendor-update/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.13-alpine

WORKDIR /app
COPY pr-template.j2 requirements.txt vendor-update.py /app/
RUN python -m pip install -U pip setuptools && pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "vendor-update.py" ]
8 changes: 8 additions & 0 deletions vendor-update/pr-template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SUMMARY
The following vendor dependencies have been updated.

| Vendor | Change |
|---|---|
{% for item in deps -%}
| {{ item.name }} | {{ item.old_version }} -> {{ item.new_version }} |
{% endfor %}
5 changes: 5 additions & 0 deletions vendor-update/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requests
packaging
PyGithub
GitPython
Jinja2
82 changes: 82 additions & 0 deletions vendor-update/vendor-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import json
import re
import sys
from pathlib import Path
import os

import requests
from git import Repo, exc
from github import Auth, Github, PullRequest
from packaging.version import parse
from jinja2 import Template


REGEX = r"(?P<name>[^\s-]+)(?P<versioned>-\d+\.\d+\.\d+)?"
UPDATED_DEPS = []
BRANCH_NAME = "vendordeps-update"
SCRIPT_PATH = Path(os.path.dirname(os.path.abspath(sys.argv[0])))
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None)
BASE_BRANCH = os.getenv("BASE_BRANCH", "main")
REPO_PATH = os.getenv("REPO_PATH", None)

if __name__ == "__main__":
auth = Auth.Token(GITHUB_TOKEN)
g = Github(auth=auth)
repo = Repo(Path.cwd())
try:
repo.delete_head(BRANCH_NAME)
except exc.GitCommandError:
pass
new_branch = repo.create_head(BRANCH_NAME)
new_branch.checkout(force=True)

_dir = Path.cwd().joinpath("vendordeps")
for file in _dir.glob("*.json"):
print(file.stem)
with file.open(mode="r", encoding="utf-8") as f:
vendor: dict = json.load(f)
file_regex = re.match(REGEX, file.stem)
json_url = vendor.get("jsonUrl", None)
version = vendor.get("version")
if json_url is None or json_url == "":
continue
new_vendor: dict = requests.get(json_url).json()
new_version = new_vendor.get("version")
if parse(new_version) <= parse(version):
continue
UPDATED_DEPS.append(
{
"name": file_regex.groupdict().get("name", None),
"old_version": version,
"new_version": new_version,
}
)
file_version = ""
if file_regex.groupdict().get("versioned", None) is not None:
file_version = f"-{new_version}"
new_file = f"{file_regex.groupdict().get("name", None)}{file_version}.json"
with _dir.joinpath(new_file).open(mode="w", encoding="utf-8") as f:
new_vendor["fileName"] = new_file
json.dump(new_vendor, f, indent=4)
file.unlink()
untracked = repo.untracked_files
diffs = [x.a_path for x in repo.index.diff(None)]
modified_deps = [x for x in untracked + diffs if x.startswith("vendordeps")]
if len(modified_deps) == 0:
print("No vendor updates")
sys.exit(0)
repo.git.add("vendordeps/*")
repo.index.commit("Updating Vendor Dependencies again")
repo.git.push("--force", "--set-upstream", "origin", repo.head.ref)

gh_repo = g.get_repo(REPO_PATH)
pulls = gh_repo.get_pulls(
state="open", sort="created", base=BASE_BRANCH, head=f"Frc5572:{BRANCH_NAME}"
)
with open(SCRIPT_PATH.joinpath("pr-template.j2")) as f:
body = Template(f.read()).render(deps=UPDATED_DEPS)
if pulls.totalCount == 0:
gh_repo.create_pull(base=BASE_BRANCH, head=BRANCH_NAME, title="Vendor Dependency Updates", body=body, draft=True)
elif pulls.totalCount == 1:
pull: PullRequest = pulls[0]
pull.edit(body=body)

0 comments on commit ab0dcbd

Please sign in to comment.