diff --git a/.github/actions/check-diff/action.yaml b/.github/actions/check-diff/action.yaml deleted file mode 100644 index f7bc91113..000000000 --- a/.github/actions/check-diff/action.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: Check diff -description: Checks that there is diff within the repository on discrete files. - -inputs: - files-to-validate: - required: true - description: "File pattern to check the diff for. (Use git's syntax)" - -runs: - using: "composite" - steps: - - name: Check diff - shell: bash - run : | - # Check diff - MODIFIED=`git status --porcelain ${{ inputs.files-to-validate }}` - - if [ -z "${MODIFIED}" ]; then - echo "Success" - exit 0 - fi - - # Ignore modification time and protoc version. - FILTERED=`git difftool -y -x "diff -I 'modTime' -I '^//.*protoc.*v'" -- ${{ inputs.files-to-validate }}` - - if [ -z "${FILTERED}" ]; then - echo "Success" - exit 0 - fi - - echo "Error: the following files don't match their committed version:" - echo "${MODIFIED}" - - DIFF=`git diff --ignore-cr-at-eol -- ${{ inputs.files-to-validate }}` - if [ -z "${DIFF}" ]; then - # If all files are only added or removed, they won't show up in the diff - exit 1 - fi - - echo "" - echo "::group::See diff" - echo "${DIFF}" - echo "::endgroup::" - exit 1 diff --git a/.github/actions/go-generate-grpc/action.yaml b/.github/actions/go-generate-grpc/action.yaml deleted file mode 100644 index 8ca33d29b..000000000 --- a/.github/actions/go-generate-grpc/action.yaml +++ /dev/null @@ -1,59 +0,0 @@ -name: Generate gRPC -description: Setup go and dependencies to generate gRPC code. - -inputs: - go-version-file: - required: true - description: "The go.mod file to be passed to the setup-go action. Globbing is allowed, the first match is the accepted one." - tools-directory: - required: true - description: "The tools module directory." - protos-directory: - required: true - description: "The directory under which the generation must happen" - enable-dart: - required: true - description: "Whether the Dart plugin is required" - -runs: - using: "composite" - steps: - - name: Install dependencies - shell: bash - run: | - # Install Protobuf compiler and git - set -eu - - DEBIAN_FRONTEND=noninteractive apt update - DEBIAN_FRONTEND=noninteractive apt install -y ca-certificates git protobuf-compiler jq curl unzip xz-utils - - name: Unglob the go-version-file - shell: bash - run: | - shopt -s globstar extglob - echo "GOVERSIONFILE=$(ls ${{ inputs.go-version-file }} | head -n 1 )" >> $GITHUB_ENV - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: ${{ env.GOVERSIONFILE }} - - name: Install go gRPC protoc generator - shell: bash - working-directory: ${{ inputs.tools-directory }} - run: | - # Install GRPC with go install - set -eu - go install google.golang.org/protobuf/cmd/protoc-gen-go \ - google.golang.org/grpc/cmd/protoc-gen-go-grpc - - uses: subosito/flutter-action@v2 - if: ${{ inputs.enable-dart == 'true' }} - with: - channel: 'stable' - flutter-version: '3.7.x' - - name: Install Dart protoc plugin - if: ${{ inputs.enable-dart == 'true' }} - shell: bash - run: | - dart pub global activate protoc_plugin - - name: Generate GRPC files - shell: bash - working-directory: ${{ inputs.protos-directory }} - run: go generate . diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 220e56e62..f33bfa50f 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -32,6 +32,9 @@ jobs: subproject: wsl-pro-service - os: ubuntu subproject: end-to-end + include: + - subproject: agentapi + needs-flutter: true runs-on: ${{ matrix.os }}-latest steps: @@ -42,40 +45,34 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Check out repository uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 + - name: Load flutter version + if: matrix.needs-flutter != '' + id: load + uses: ./.github/actions/load-json with: - go-version-file: ${{ matrix.subproject }}/go.mod - - name: Update module files - shell: bash - if: always() && !cancelled() - working-directory: ${{ matrix.subproject }} - run: | - # Ensuring there is no diff between current and generated go.mod and go.sum files - set -eu - - echo "::group::Download dependencies" - go mod tidy - echo "::endgroup::" - - name: Ensure module files are up to date - uses: ./.github/actions/check-diff + path: tools/versions.json + - name: Set up flutter + uses: subosito/flutter-action@v2 + if: matrix.needs-flutter != '' with: - files-to-validate: ${{ matrix.subproject }}/**/go.mod ${{ matrix.subproject }}/**/go.sum - - name: Build + channel: 'stable' + flutter-version: ${{ steps.load.outputs.data.flutter-version }} + - name: Install Dart protoc plugin + if: matrix.needs-flutter != '' shell: bash - if: always() && !cancelled() working-directory: ${{ matrix.subproject }} run: | - go build -tags=gowslmock ./... - - name: Linter - uses: golangci/golangci-lint-action@v3 - if: always() && !cancelled() + dart pub global activate protoc_plugin + - name: Quality check + uses: canonical/desktop-engineering/gh-actions/go/code-sanity@main with: - version: v1.54.2 - args: --config=${{ github.workspace }}/.golangci.yaml --build-tags=gowslmock working-directory: ${{ matrix.subproject }} + go-tags: gowslmock + tools-directory: ${{ github.workspace }}/tools + golangci-lint-configfile: ${{ github.workspace }}/.golangci.yaml - name: Gettext validation shell: bash + working-directory: ${{ matrix.subproject }} run: | set -eu @@ -94,7 +91,7 @@ jobs: fail-fast: false matrix: os: [ubuntu, windows] - package: ["gui/packages/p4w_ms_store", "gui/packages/ubuntupro"] + package: ["p4w_ms_store", "ubuntupro"] runs-on: ${{ matrix.os }}-latest steps: - name: Set up git @@ -111,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Go # We need to set up Go so that the agent can be built for the end-to-end tests - if: matrix.package == 'gui/packages/ubuntupro' + if: matrix.package == 'ubuntupro' uses: actions/setup-go@v4 with: go-version-file: windows-agent/go.mod @@ -124,11 +121,14 @@ jobs: uses: ./.github/actions/flutter-qa/ with: flutter-version: ${{ steps.load.outputs.data.flutter-version }} - package-dir: '${{ matrix.package }}' - run-build-runner: ${{ contains(matrix.package, 'ubuntupro') }} - - uses: ./.github/actions/check-diff + package-dir: gui/packages/${{ matrix.package }} + run-build-runner: ${{ matrix.package == 'ubuntupro' }} + - name: Ensure module files are up to date + uses: canonical/desktop-engineering/gh-actions/common/has-diff@main with: - files-to-validate: '${{ matrix.package }}/**/*.dart' + working-directory: gui/packages/${{ matrix.package }} + paths-to-ignore: ${{ matrix.package == 'ubuntupro' && 'pubspec.lock' || '' }} + fail-on-diff: true flutter-integration: name: "Flutter integration tests" @@ -231,35 +231,3 @@ jobs: # uses: codecov/codecov-action@v3 # with: # file: /tmp/coverage.out - - generated-grpc: - name: gRPC files are up to date - runs-on: ubuntu-latest - container: ubuntu:rolling - strategy: - fail-fast: false - matrix: - subproject: ["agentapi", "wslserviceapi"] - steps: - - name: Install git into the container - run: | - set -eu - DEBIAN_FRONTEND=noninteractive apt update - DEBIAN_FRONTEND=noninteractive apt install -y git - - name: Set up git - # This step needs to be done before checkout so that the checkout respects clrf - uses: canonical/ubuntu-pro-for-windows/.github/actions/setup-git@main - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Check out repository - uses: actions/checkout@v4 - - uses: ./.github/actions/go-generate-grpc - with: - go-version-file: ${{ matrix.subproject }}/**/go.mod - tools-directory: tools - protos-directory: ${{ matrix.subproject }} - enable-dart: ${{ matrix.subproject == 'agentapi' }} - - name: Ensure generated gRPC files are up to date - uses: ./.github/actions/check-diff - with: - files-to-validate: '${{ matrix.subproject }}/{.,**}/*.{dart,go}' diff --git a/agentapi/generate.ps1 b/agentapi/generate.ps1 new file mode 100644 index 000000000..fab4ac965 --- /dev/null +++ b/agentapi/generate.ps1 @@ -0,0 +1,5 @@ +${env:PATH}="${env:PATH};$(go env GOPATH)\bin" +${env:PATH}="${env:PATH};${env:LocalAppData}\Pub\Cache\bin" + +protoc.exe --proto_path=. --go_out="go/" --go_opt=paths=source_relative --go-grpc_out="go/" --go-grpc_opt=paths=source_relative "agentapi.proto" +protoc.exe --proto_path=. --dart_out="grpc:dart/lib/src/" "agentapi.proto" \ No newline at end of file diff --git a/agentapi/generator_windows.go b/agentapi/generator_windows.go index fcbd86848..a810820d1 100644 --- a/agentapi/generator_windows.go +++ b/agentapi/generator_windows.go @@ -1,6 +1,4 @@ // Package agentapi allows generated API bindings from GRPC definitions. package agentapi -//go:generate wsl -- bash -c "source ~/.profile && ./generate.sh" - -// Sourcing.profile because wsl --