From 3c54edb3034f9c4fb18a6c1edb6744523348348d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Wed, 6 Sep 2023 16:57:36 +0200 Subject: [PATCH] Implement workspace internal dependency updater --- .../update-workspace-dependencies/action.yaml | 20 ++++++++++++ .../update-workspace-dependencies.sh | 32 +++++++++++++++++++ .github/workflows/auto-updates.yaml | 30 +++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .github/actions/update-workspace-dependencies/action.yaml create mode 100644 .github/actions/update-workspace-dependencies/update-workspace-dependencies.sh 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..98b3d3d17 --- /dev/null +++ b/.github/actions/update-workspace-dependencies/update-workspace-dependencies.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -eu + +repo="github.com/${GITHUB_ACTION_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..9fd63de2a 100644 --- a/.github/workflows/auto-updates.yaml +++ b/.github/workflows/auto-updates.yaml @@ -116,3 +116,33 @@ 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: 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