Skip to content

Commit

Permalink
Selective updates
Browse files Browse the repository at this point in the history
Only the WSL-Pro-Service needs to stay up-to-date.
And we only need to update modules when these have changed
  • Loading branch information
EduardGomezEscandell committed Sep 12, 2023
1 parent f411abe commit 26f7e99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
6 changes: 4 additions & 2 deletions .github/actions/update-workspace-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Update Workspace dependencies
description: Updates internal dependencies in a Go Workspace

inputs:
token:
description: Github token
module:
description: The go module to update the dependencies of
required: true

runs:
Expand All @@ -17,4 +17,6 @@ runs:
- name: Update workspace dependencies
shell: bash
run: ${{ github.action_path }}/update-workspace-dependencies.sh
env:
TARGET_MODULE: ${{ inputs.module }}

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

cd ${TARGET_MODULE}
current_commit=$(git rev-parse HEAD~0)

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

# Gather all go modules
modules=$(go work edit -json \
| jq -r '.Use | keys[] as $k | "\(.[$k].DiskPath)"' \
| sed $'s#\.\/##' \
)
for dependency in ${dependencies}; do
pattern="^${repo}/\(.*\)@v\([^-]\+\)-\([^-]\+\)-\(.*\)$"
# Capture groups: (https://go.dev/ref/mod#versions)
# \1 Dependency path
# \2 Base version prefix
# \3 Timestamp
# \4 Revision identifier (12-character prefix of the commit hash)

# Find internal dependencies
for mod in ${modules} ; do
cd "${mod}"
echo "::group::Updating module ${mod}::"
dep_path=`echo $dependency | sed "s#${pattern}#\1#"`
dep_commit=`echo $dependency | sed "s#${pattern}#\4#"`

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
diff_files="$(git diff --name-only ${dep_commit} -- "../${dep_path}")"
if [ -z "${diff_files}" ] ; then
continue
fi

echo "::group::Updating dependency ${dep_path}::"

echo "Files changed since commit ${dep_commit}:"
echo "${diff_files}"

go get "${repo}/${dep_path}@${current_commit}"

go mod tidy

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

go work sync
7 changes: 3 additions & 4 deletions .github/workflows/auto-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ jobs:
go-version-file: go.work
- name: Update submodules
uses: ./.github/actions/update-workspace-dependencies
with:
module: wsl-pro-service
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: Auto update internal dependencies
title: Auto update internal dependencies
title: Auto update WSL-Pro-Service 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 26f7e99

Please sign in to comment.