Skip to content

Commit

Permalink
Implement workspace internal dependency updater
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Sep 7, 2023
1 parent 844a4da commit d2a2895
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/actions/update-workspace-dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Update Workspace dependencies
description: Updates internal dependencies in a Go Workspace

inputs:
token:
description: Github token
required: true

runs:
using: "composite"
steps:
- name: Install dependencies
shell: bash
run: |
sudo DEBIAN_FRONTEND=noninteractive apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y jq
- name: Update workspace dependencies
shell: bash
run: ${{ github.action_path }}/update-workspace-dependencies.sh

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -eu

repo="github.com/${GITHUB_REPOSITORY}"

# Gather all go modules
modules=$(go work edit -json \
| jq -r '.Use | keys[] as $k | "\(.[$k].DiskPath)"' \
| sed $'s#\.\/##' \
)

# Find internal dependencies
for mod in ${modules} ; do
cd "${mod}"
echo "::group::Updating module ${mod}::"

url="${repo}/${mod}"
regex="s#${url} \(${repo}/[^@]\+\)@v.*#\1#p"
dependencies=`go mod graph | sed -n "${regex}"`

for dep in ${dependencies}; do
go get "${dep}@main"
done

go mod tidy

echo "Done"
echo "::endgroup::"
cd ~-
done

go work sync
34 changes: 34 additions & 0 deletions .github/workflows/auto-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,37 @@ jobs:
if: steps.check-readme.outputs.modified == 'true'
run: |
git push origin auto-updates/readme-cli-ref:main
update-internal-dependencies:
name: Update internal dependencies
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: main
- name: Set up git
uses: ./.github/actions/setup-git
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up go
uses: actions/setup-go@v4
with:
go-version-file: go.work
- name: Update submodules
uses: ./.github/actions/update-workspace-dependencies
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: Auto update internal dependencies
title: Auto update internal dependencies
labels: automated pr
body: "[Auto-generated pull request](https://github.com/canonical/ubuntu-pro-for-windows/actions/workflows/auto-updates.yaml) by GitHub Action"
branch: auto-updates/update-internal-dependencies
token: ${{ secrets.GITHUB_TOKEN }}
- name: Push branch
run: |
git push origin auto-updates/update-internal-dependencies:main

0 comments on commit d2a2895

Please sign in to comment.