Skip to content

Commit

Permalink
Add install-go make targets and cleanup lint / project
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Mar 6, 2025
1 parent 47f793f commit a2c5cd0
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 91 deletions.
135 changes: 84 additions & 51 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,108 @@ on:
pull_request:

env:
GO_VERSION: 1.24.x
GO_VERSION: 1.24
GOTOOLCHAIN: local
GO_INSTALL_DESTINATION: /opt

jobs:
go:
go_current:
timeout-minutes: 5
name: "go | ${{ matrix.goos }} | ${{ matrix.canary }}"
runs-on: "${{ matrix.os }}"
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
goos: linux
- os: ubuntu-24.04
goos: freebsd
# FIXME: this is currently failing in a non-sensical way, so, running on linux instead...
# - os: windows-2022
- os: ubuntu-24.04
goos: windows
- os: ubuntu-24.04
goos: linux
# This allows the canary script to select any upcoming golang alpha/beta/RC
canary: go-canary
name: "go stable"
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- name: Environment setup
run: |
echo "GO_VERSION=$(make install-go-resolve-version)" >> "$GITHUB_ENV"
echo "PATH=$GO_INSTALL_DESTINATION/go/bin:$HOME/go/bin:$PATH" >> "$GITHUB_ENV"
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
id: cache-go
with:
path: /opt/go
key: golang-${{ env.GO_VERSION }}
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
id: cache-go-dev
with:
path: ~/go/bin
key: golang-dev-${{ env.GO_VERSION }}-${{ hashFiles('Makefile') }}
- if: ${{ steps.cache-go.outputs.cache-hit != 'true' }}
name: Install go
continue-on-error: false
run: make install-go
- if: ${{ steps.cache-go-dev.outputs.cache-hit != 'true' }}
name: Install dev tools
continue-on-error: false
run: make install-dev-tools

- name: project checks
uses: containerd/project-checks@d7751f3c375b8fe4a84c02a068184ee4c1f59bc4 # v1.2.2
with:
working-directory: src/github.com/containerd/nerdctl
repo-access-token: ${{ secrets.GITHUB_TOKEN }}
# go-licenses-ignore is set because go-licenses cannot detect the license of the following package:
# * go-base36: Apache-2.0 OR MIT (https://github.com/multiformats/go-base36/blob/master/LICENSE.md)
#
# The list of the CNCF-approved licenses can be found here:
# https://github.com/cncf/foundation/blob/main/allowed-third-party-license-policy.md
go-licenses-ignore: |
github.com/multiformats/go-base36
- name: imports
run: make lint-imports
- name: mod
run: make lint-mod
- name: go
run: make lint-go-all

go_canary:
timeout-minutes: 5
name: "go canary"
runs-on: ubuntu-24.04
env:
GOOS: "${{ matrix.goos }}"
GO_VERSION: canary
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- name: Set GO env
- name: Environment setup
run: |
# If canary is specified, get the latest available golang pre-release instead of the major version
if [ "$canary" != "" ]; then
. ./hack/build-integration-canary.sh
canary::golang::latest
fi
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
echo "GO_VERSION=$(make install-go-resolve-version)" >> "$GITHUB_ENV"
echo "PATH=$GO_INSTALL_DESTINATION/go/bin:$HOME/go/bin:$PATH" >> "$GITHUB_ENV"
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
id: cache-go
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
path: /opt/go
key: golang-${{ env.GO_VERSION }}
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
id: cache-go-dev
with:
args: --verbose
# See https://github.com/containerd/nerdctl/issues/3914
verify: false
path: ~/go/bin
key: golang-dev-${{ env.GO_VERSION }}-${{ hashFiles('Makefile') }}
- if: ${{ steps.cache-go.outputs.cache-hit != 'true' }}
name: Install go
run: make install-go
- if: ${{ steps.cache-go-dev.outputs.cache-hit != 'true' }}
name: Install dev tools
run: make install-dev-tools

- name: imports
run: make lint-imports
- name: mod
run: make lint-mod
- name: go
run: make lint-go-all

other:
timeout-minutes: 5
name: yaml | shell | imports order
name: "yaml | shell"
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: install required linters and dev-tools
run: |
make install-dev-tools
- name: yaml
- name: make lint-yaml
run: make lint-yaml
- name: shell
- name: make lint-shell
run: make lint-shell
- name: go imports ordering
run: |
make lint-imports
39 changes: 0 additions & 39 deletions .github/workflows/project.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ RUN os="${BUILDPLATFORM%%/*}"; \
candidates="$(case "$GO_VERSION" in \
canary) condition=".stable==false" ;; \
stable|"") condition=".stable==true" ;; \
*) condition='.version=="go'"$GO_VERSION"'"' ;; \
*) condition='.version | startswith("go'"$GO_VERSION"'")' ;; \
esac; \
jq -rc 'map(select('"$condition"'))[0].files | map(select(.os=="'"$os"'"))' <(printf "$all_versions"))"; \
arch=arm64; \
Expand Down
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ GO_BUILD_FLAGS ?=
##########################
# Helpers
##########################
ARCH := amd64
ifeq ($(shell uname -m), aarch64)
ARCH = arm64
endif
OS := linux
ifeq ($(shell uname -s), Darwin)
OS = darwin
endif
ifeq ($(shell uname -s), FreeBSD)
OS = freebsd
endif

ifdef VERBOSE
VERBOSE_FLAG := -v
VERBOSE_FLAG_LONG := --verbose
Expand Down Expand Up @@ -233,6 +245,38 @@ install-dev-tools:
@echo "Remember to add GOROOT/bin to your path"
$(call footer, $@)


GO_VERSION ?= stable
GO_VERSION_SELECTOR =
GO_VERSION_SELECTOR = .version | startswith("go$(GO_VERSION)")
ifeq ($(GO_VERSION),canary)
GO_VERSION_SELECTOR = .stable==false
endif
ifeq ($(GO_VERSION),stable)
GO_VERSION_SELECTOR = .stable==true
endif
ifeq ($(GO_VERSION),)
GO_VERSION_SELECTOR = .stable==true
endif

GO_INSTALL_DESTINATION ?= /opt/$(BINARY)-dev-tools

install-go:
$(call title, $@)
@mkdir -p $(GO_INSTALL_DESTINATION)
@if [ ! -e $(GO_INSTALL_DESTINATION)/go ]; then curl -fsSL --proto '=https' --tlsv1.2 https://go.dev/dl/$(shell curl -fsSL --proto "=https" --tlsv1.3 "https://go.dev/dl/?mode=json&include=all" | \
jq -rc 'map(select($(GO_VERSION_SELECTOR)))[0].files | map(select(.os=="$(OS)" and .arch=="$(ARCH)"))[0].filename') | \
tar xzC $(GO_INSTALL_DESTINATION) || exit; \
else \
echo "Install already detected, doing nothing."; \
fi
@echo Remember to add to your profile: export PATH="$(GO_INSTALL_DESTINATION)/go/bin:\$$HOME/go/bin:\$$PATH"
$(call footer, $@)

install-go-resolve-version:
@curl -fsSL --proto "=https" --tlsv1.2 "https://go.dev/dl/?mode=json&include=all" | \
jq -rc 'map(select($(GO_VERSION_SELECTOR)))[0].version' | sed s/go//

##########################
# Testing tasks
##########################
Expand Down

0 comments on commit a2c5cd0

Please sign in to comment.