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

Implement workspace internal dependency updater #262

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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}
didrocks marked this conversation as resolved.
Show resolved Hide resolved
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