diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 893debbf7..d678e3ebb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,34 +104,6 @@ jobs: - name: check commits run: scripts/check-each-commit.sh upstream/master - ######################## - # check submodules - ######################## - check-submodules: - name: check submodules - runs-on: ubuntu-latest - steps: - - name: git checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 - with: - go-version: '${{ env.GO_VERSION }}' - - - name: fetch and rebase on master - run: | - git remote add upstream https://github.com/lightningnetwork/lnd - git fetch upstream - export GIT_COMMITTER_EMAIL="lnd-ci@example.com" - export GIT_COMMITTER_NAME="LND CI" - git rebase upstream/master - - - name: check submodules - run: scripts/check-submodule-version.sh upstream/master - ######################## # lint code ######################## diff --git a/docs/code_contribution_guidelines.md b/docs/code_contribution_guidelines.md index 980d021fc..23565164d 100644 --- a/docs/code_contribution_guidelines.md +++ b/docs/code_contribution_guidelines.md @@ -12,6 +12,7 @@ 1. [Code Spacing and formatting](#code-spacing-and-formatting) 1. [Pointing to Remote Dependent Branches in Go Modules](#pointing-to-remote-dependent-branches-in-go-modules) 1. [Use of Log Levels](#use-of-log-levels) + 1. [Use of Golang submodules](#use-of-golang-submodules) 5. [Code Approval Process](#code-approval-process) 1. [Code Review](#code-review) 1. [Rework Code (if needed)](#rework-code-if-needed) @@ -640,6 +641,24 @@ Only use `error` for internal errors that are never expected to happen during normal operation. No event triggered by external sources (rpc, chain backend, etc) should lead to an `error` log. +## Use of Golang submodules + +Changes to packages that are their own submodules (e.g. they contain a `go.mod` +and `go.sum` file, for example `tor/go.mod`) require a specific process. +We want to avoid the use of local replace directives in the root `go.mod`, +therefore changes to a submodule are a bit involved. + +The main process for updating and then using code in a submodule is as follows: + - Create a PR for the changes to the submodule itself (e.g. edit something in + the `tor` package) + - Wait for the PR to be merged and a new tag (for example `tor/v1.0.x`) to be + pushed. + - Create a second PR that bumps the updated submodule in the root `go.mod` and + uses the new functionality in the main module. + +Of course the two PRs can be opened at the same time and be built on top of each +other. But the merge and tag push order should always be maintained. + # Code Approval Process This section describes the code approval process that is used for code diff --git a/scripts/check-submodule-version.sh b/scripts/check-submodule-version.sh deleted file mode 100755 index f3685356e..000000000 --- a/scripts/check-submodule-version.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -ROOT_MODULE="github.com/lightningnetwork/lnd" - -# The command 'go list -m all' returns all imports in the following format: -# github.com/lightningnetwork/lnd/cert v1.1.0 => ./cert -# The two cut then first split by spaces and then by slashes to extract the -# submodule names. -SUBMODULES="$(go list -m all | grep $ROOT_MODULE/ | cut -d' ' -f1 | cut -d'/' -f4-)" -BRANCH=$1 - -for m in $SUBMODULES; do - has_changes=0 - git diff --stat $BRANCH.. | grep -q " $m/" && has_changes=1 - - if [[ $has_changes -eq 1 ]]; then - has_bump=0 - git diff $BRANCH.. -- go.mod | \ - grep -q "^\+[[:space:]]*$ROOT_MODULE/$m " && has_bump=1 - - if [[ $has_bump -eq 0 ]]; then - echo "Submodule '$m' has changes but no version bump in go.mod was found" - echo "If you update code in a submodule, you must bump its version in " - echo "go.mod to the _next_ version so a tag for that version can be" - echo "pushed after merging the PR." - exit 1 - else - echo "Submodule '$m' has changes but go.mod bumps it to: " - git diff $BRANCH.. -- go.mod | grep $m - fi - else - echo "Submodule '$m' has no changes, skipping" - fi -done