Skip to content

Commit

Permalink
Add auto update ability
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Oct 16, 2023
1 parent d0232d4 commit b368fdf
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/auto_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Auto Update
on:
workflow_dispatch:
schedule:
# Check on Mondays and Thursdays
- cron: '0 0 * * 1,4'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
auto_update_module:
name: "Auto Update Module"
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.20.x
id: go

- uses: actions/checkout@v3

- name: Install Buildifier
run: |
cd $(mktemp -d)
GO111MODULE=on go install github.com/bazelbuild/buildtools/buildifier@latest
# Checkout repository
- uses: actions/checkout@v3
with:
path: libraries/rules_bzlmodrio_toolchains

# Checkout gentool
- uses: actions/checkout@v3
with:
repository: 'bzlmodRio/gentool.git'
fetch-depth: 0
path: gentool
ref: refactor_dev


- name: Setup Cache
uses: actions/cache@v3
with:
path: |
~/bzlmod_cache/*.sha256
key: ${{ runner.os }}-${{ hashFiles('**/generate/**') }}
restore-keys: |
${{ runner.os }}-
${{ runner.os }}
# Run update
- name: Run update
run: bazel run //:auto_update
working-directory: libraries/rules_bzlmodrio_toolchains/generate

- name: Generate if changed
run: |
if [[ $(git --no-pager diff --exit-code HEAD) != '' ]]; then
echo "Something changed, need to re-generate"
bazel run //:generate
buildifier -warnings all --lint=fix -r ..
else
echo "No changes!"
fi;
working-directory: libraries/rules_bzlmodrio_toolchains/generate

- name: Store new version
run: echo "NEW_VERSION=$(bazel run //:get_version)" >> $GITHUB_ENV
working-directory: libraries/rules_bzlmodrio_toolchains/generate

# Create pull requests
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_KEY }}
with:
path: libraries/rules_bzlmodrio_toolchains
base: main
token: ${{ secrets.AUTO_UPDATE_KEY }}
reviewers: pjreiniger
branch: autoupdate_${{ env.NEW_VERSION }}
title: "Auto Update to '${{ env.NEW_VERSION }}'"
28 changes: 28 additions & 0 deletions generate/auto_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import re
from bazelrio_gentool.auto_update_utils import get_latest_tag, split_tag


def main():
latest_tag = get_latest_tag("wpilibsuite", "opensdk")

overall_year, overall_version = latest_tag[1:].split("-")

SCRIPT_DIR = os.environ["BUILD_WORKSPACE_DIRECTORY"]

file_to_replace = os.path.join(SCRIPT_DIR, "get_toolchain_dependencies.py")

with open(file_to_replace, "r") as f:
contents = f.read()

contents = re.sub('( +)overall_year = "(.*)"', f'\\1overall_year = "{overall_year}"', contents)
contents = re.sub(
'( +)overall_version = f?"(.*)"', f'\\1overall_version = "{overall_version}"', contents
)

with open(file_to_replace, "w") as f:
f.write(contents)


if __name__ == "__main__":
main()

0 comments on commit b368fdf

Please sign in to comment.