diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a895af440..c53bdaae7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,170 +8,142 @@ on: paths-ignore: - 'scripts/**' - '**/*.md' + push: + # Build for the master branch. + branches: + - master + release: + # Publish released commit as Docker `latest` and `git_revision` images. + types: + - published workflow_dispatch: inputs: ref: description: 'Ref to build CLI for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' required: false default: '' + push_image: + description: 'Push images to DockerHub [default: false; examples: true, false]' + required: false + default: 'false' + use_latest_tag: + description: 'Use `latest` tag while pushing images to DockerHub (applied to Ubuntu image only) [default: false; examples: true, false]' + required: false + default: 'false' env: GO111MODULE: "on" jobs: - build_cli_ubuntu: - name: Build CLI (Ubuntu) - runs-on: ubuntu-20.04 + build_cli: + name: Build CLI + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-20.04, windows-2022, macos-12] + arch: [amd64, arm64] + exclude: + - os: windows-2022 + arch: 'arm64' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.event.inputs.ref }} # Allows to fetch all history for all branches and tags. Need this for proper versioning. fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.18 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} + cache: true - name: Update Go modules run: go mod download -json - name: Build CLI run: make build + env: + GOARCH: ${{ matrix.arch }} - name: Upload artifact uses: actions/upload-artifact@v2 with: - name: neo-go-binaries-ubuntu - path: ./bin/neo-go + name: neo-go-${{ matrix.os }}-${{ matrix.arch }} + path: ./bin/neo-go* if-no-files-found: error - build_cli_wsc: - name: Build CLI (Windows Server Core) - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Build CLI - run: make build - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: neo-go-binaries-wsc - path: ./bin/neo-go.exe - if-no-files-found: error - - build_image_ubuntu: - needs: build_cli_ubuntu - name: Build Docker image (Ubuntu) + build_image: + needs: build_cli + name: Build and push docker image runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.event.inputs.ref }} fetch-depth: 0 - # For proper `deps` make target execution. - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 + - name: Set up QEMU + if: runner.os != 'Windows' + uses: docker/setup-qemu-action@v2 - - name: Build Docker image - run: make image + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Set vars + id: setvars + run: make gh-docker-vars + + - name: Set latest tag + id: setlatest + if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true' && github.event.inputs.use_latest_tag == 'true') }} + run: echo "::set-output name=latest::,${{ steps.setvars.outputs.repo }}:latest" + + - name: Build and push + uses: docker/build-push-action@v3 + with: + push: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + platforms: linux/amd64,linux/arm64 + build-args: | + REPO=${{ steps.setvars.outputs.repo }} + VERSION=${{ steps.setvars.outputs.version }} + tags: ${{ steps.setvars.outputs.repo }}:${{ steps.setvars.outputs.version }}${{ steps.setvars.outputs.suffix }}${{ steps.setlatest.outputs.latest }} build_image_wsc: - needs: build_cli_wsc - name: Build Docker image (Windows Server Core) + needs: build_cli + name: Build and push docker image (Windows Server Core) runs-on: windows-2022 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.event.inputs.ref }} fetch-depth: 0 # For proper `deps` make target execution. - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.18 + cache: true + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Build Docker image run: make image - build_privnet_image_ubuntu: - needs: build_cli_ubuntu - name: Build privnet Docker image (Ubuntu) - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - fetch-depth: 0 - - # For proper `deps` make target execution. - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - # For information purposes. - - name: Print Docker version - run: docker --version - - - name: Build privnet Docker image - run: make env_image - - build_privnet_image_wsc: - needs: build_cli_wsc - name: Build privnet Docker image (Windows Server Core) - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - fetch-depth: 0 - - # For proper `deps` make target execution. - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - # For information purposes. - - name: Print Docker version - run: docker --version - - - name: Build privnet Docker image - run: make env_image + - name: Push image to registry + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + run: make image-push diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index b88d3cb8e..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master, master-2.x ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '35 8 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'go' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/publish_to_dockerhub.yml b/.github/workflows/publish_to_dockerhub.yml deleted file mode 100644 index d8cf5e969..000000000 --- a/.github/workflows/publish_to_dockerhub.yml +++ /dev/null @@ -1,169 +0,0 @@ -name: Push images to DockerHub - -# Controls when the action will run. -on: - push: - # Publish `master` as Docker `latest` and `git_revision` images. - branches: - - master - release: - # Publish released commit as Docker `latest` and `git_revision` images. - types: - - published - - # Allows to run this workflow manually from the Actions tab. - workflow_dispatch: - inputs: - ref: - description: 'Ref to build Docker images for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' - required: false - default: '' - push_image: - description: 'Push images to DockerHub [default: false; examples: true, false]' - required: false - default: 'false' - use_latest_tag: - description: 'Use `latest` tag while pushing images to DockerHub (applied to Ubuntu image only) [default: false; examples: true, false]' - required: false - default: 'false' - -# Environment variables. -env: - GO111MODULE: "on" - -# A workflow run. -jobs: - tests_ubuntu: - name: Run Ubuntu-based tests before publishing - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - # Allows to fetch all history for all branches and tags. Need this for proper versioning. - fetch-depth: 0 - - - name: Sync VM submodule - run: | - git submodule sync - git submodule update --init - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Restore go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Run tests - run: make test - publish_ubuntu: - # Ensure test job passes before pushing image. - needs: tests_ubuntu - name: Publish Ubuntu-based image to DockerHub - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - # Allows to fetch all history for all branches and tags. Need this for proper versioning. - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Build image - run: make image - - - name: Build image with 'latest' tag - if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true' && github.event.inputs.use_latest_tag == 'true') }} - run: make image-latest - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Push image to registry - if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - run: make image-push - - - name: Push image with 'latest' tag to registry - if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true' && github.event.inputs.use_latest_tag == 'true') }} - run: make image-push-latest - - tests_wsc: - name: Run WindowsServerCore-based tests before publishing - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - # Allows to fetch all history for all branches and tags. Need this for proper versioning. - fetch-depth: 0 - - - name: Sync VM submodule - run: | - git submodule sync - git submodule update --init - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Restore go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Run tests - run: make test - publish_wsc: - # Ensure test job passes before pushing image. - needs: tests_wsc - name: Publish WindowsServerCore-based image to DockerHub - runs-on: windows-2022 - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.ref }} - # Allows to fetch all history for all branches and tags. Need this for proper versioning. - fetch-depth: 0 - - - name: Show docker images - run: docker images - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Build image - run: make image - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Push image to registry - if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - run: make image-push diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 250d9882a..adef34a96 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -1,6 +1,8 @@ name: Tests on: + push: + branches: [ master ] pull_request: branches: - master @@ -19,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: @@ -30,13 +32,58 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Check dependencies run: | ./scripts/check_deps.sh + codeql: + name: CodeQL + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + test_cover: name: Coverage runs-on: ubuntu-20.04 @@ -44,7 +91,7 @@ jobs: env: CGO_ENABLED: 0 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -54,15 +101,10 @@ jobs: git submodule update --init - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.18 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} + cache: true - name: Update Go modules run: go mod download -json @@ -82,33 +124,32 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2022] + os: [ubuntu-20.04, windows-2022, macos-12] go_versions: [ '1.16', '1.17', '1.18' ] exclude: - # Only latest Go version for Windows. + # Only latest Go version for Windows and MacOS. - os: windows-2022 go_versions: '1.16' - os: windows-2022 go_versions: '1.17' + - os: macos-12 + go_versions: '1.16' + - os: macos-12 + go_versions: '1.17' # Exclude latest Go version for Ubuntu as Coverage uses it. - os: ubuntu-20.04 go_versions: '1.18' fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: '${{ matrix.go_versions }}' - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} + cache: true - name: Update Go modules run: go mod download -json diff --git a/Makefile b/Makefile index 9c8b4fcb6..3ad6298c0 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ IMAGE_REPO=nspccdev/neo-go # All of the targets are phony here because we don't really use make dependency # tracking for files -.PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest check-version clean-cluster push-tag \ - test vet lint fmt cover +.PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest clean-cluster \ + test vet lint fmt cover version gh-docker-vars build: deps @echo "=> Building binary" @@ -86,20 +86,20 @@ image-push-latest: @echo "=> Publish image for Ubuntu with 'latest' tag" @docker push $(IMAGE_REPO):latest -check-version: - git fetch && (! git rev-list ${VERSION}) - deps: @CGO_ENABLED=0 \ go mod download @CGO_ENABLED=0 \ go mod tidy -v -push-tag: - git checkout ${BRANCH} - git pull origin ${BRANCH} - git tag ${VERSION} - git push origin ${VERSION} +version: + @echo $(VERSION) + +gh-docker-vars: + @echo "::set-output name=file::$(D_FILE)" + @echo "::set-output name=version::$(VERSION)" + @echo "::set-output name=repo::$(REPO)" + @echo "::set-output name=suffix::$(IMAGE_SUFFIX)" test: @go test ./... -cover