diff --git a/.github/actions/update-workspace-dependencies/action.yaml b/.github/actions/update-workspace-dependencies/action.yaml new file mode 100644 index 000000000..0dd5e66c0 --- /dev/null +++ b/.github/actions/update-workspace-dependencies/action.yaml @@ -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 + diff --git a/.github/actions/update-workspace-dependencies/update-workspace-dependencies.sh b/.github/actions/update-workspace-dependencies/update-workspace-dependencies.sh new file mode 100644 index 000000000..3299c3f9b --- /dev/null +++ b/.github/actions/update-workspace-dependencies/update-workspace-dependencies.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/auto-updates.yaml b/.github/workflows/auto-updates.yaml index 0141825d0..d77e2d8fe 100644 --- a/.github/workflows/auto-updates.yaml +++ b/.github/workflows/auto-updates.yaml @@ -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 + + + \ No newline at end of file