Why can I run Go tests and builds in a CI environment without installing dependencies first?

WBOY
Release: 2024-02-13 08:42:19
forward
600 people have browsed it

为什么可以在 CI 环境中运行 Go 测试和构建而无需先安装依赖项?

The reason why you don’t need to install dependencies first when running Go tests and builds in a CI environment is because the CI (Continuous Integration) tool can automatically download and install the required ones on every build dependencies. The advantage of this is that it reduces the burden on developers and does not require manual maintenance of dependency installation and updates. At the same time, CI tools can also ensure that each build is performed in the same environment, avoiding build failures or inconsistent results due to inconsistent dependency versions. Therefore, when running Go tests and builds in a CI environment, development and testing work can be performed more conveniently and efficiently.

Question content

I have a go project with a makefile

test:
    @go test -cover ./...
Copy after login

And a mod file

module path/to/repo

go 1.19

require github.com/go-chi/chi/v5 v5.0.8
Copy after login

I created a github action example to run tests on github pr

name: QA on pull request

on: pull_request

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Setup Go
        uses: actions/setup-go@v3
        with:
          go-version: 1.19

      - name: Run tests
        run: make test
Copy after login

I want to know why this workflow works without the install dependency step. The project itself is using external dependencies and I think there should be a step to run go get ./...

If they do not exist, will go install them in the background? Or does the actions/setup-go@v3 action install dependencies?

Workaround

According to the go test documentation (or you can run go help test locally to read its description):

"Go test" recompiles every package and any file whose name matches the file pattern "*_test.go".

It also installs all dependencies; therefore, this happens when the action go test is executed. You may be able to observe it in the logs.

actions/setup-go@v3 Does not depend on the code itself. It just sets up the go environment you requested. In your setup, if you swap setup-go and checkout, it will still work.

The above is the detailed content of Why can I run Go tests and builds in a CI environment without installing dependencies first?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!