Skip to content

Commit

Permalink
tool: add a script to centralize golang version update (#219)
Browse files Browse the repository at this point in the history
* apply linter on .github/workflow files

* Add script to centralise golang version update

the script is taking the golang version present in the go.mod file and apply
patch on the differents files that contains the golang version. for example
Dockerfile and github workflow files.

* update after comments
  • Loading branch information
clamoriniere authored Jul 10, 2024
1 parent 02ebc32 commit 272d0da
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 93 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: build

env:
GO_VERSION: 1.21

on:
push:

jobs:
build-linux-binary:
runs-on: ubuntu-latest
Expand Down
83 changes: 37 additions & 46 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: "CodeQL"

env:
GO_VERSION: 1.21

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

branches: [main]
jobs:
analyze:
name: Analyze
Expand All @@ -18,51 +15,45 @@ jobs:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
language: ['go']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

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#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
# see doc: https://github.com/github/codeql-action
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Install required packages
uses: mstksg/get-package@v1
with:
apt-get: mercurial jq build-essential
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Install tools
run: |
make install-tools
- name: Run build
run: |
- 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#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
# see doc: https://github.com/github/codeql-action
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Install required packages
uses: mstksg/get-package@v1
with:
apt-get: mercurial jq build-essential
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Install tools
run: |
make install-tools
- name: Run build
run: |
make manager
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
18 changes: 9 additions & 9 deletions .github/workflows/pr-linter.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: pull request linter
on:
pull_request_target:
types: [opened, labeled, unlabeled, synchronize]
types: [opened, labeled, unlabeled, synchronize]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Verify Pull Request Labels
uses: jesusvasquez333/[email protected]
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
valid-labels: 'bug, enhancement, refactoring, documentation, tooling, dependencies'
pull-request-number: '${{ github.event.pull_request.number }}'
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Verify Pull Request Labels
uses: jesusvasquez333/[email protected]
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
valid-labels: 'bug, enhancement, refactoring, documentation, tooling, dependencies'
pull-request-number: '${{ github.event.pull_request.number }}'
check-milestone:
name: Check Milestone
runs-on: ubuntu-latest
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: Release

env:
GO_VERSION: 1.21

on:
push:
branches:
- "v[0-9]+.[0-9]+"
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"

jobs:
build-linux-binary:
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -33,9 +30,9 @@ jobs:
id: latest_version
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
Expand Down Expand Up @@ -69,9 +66,9 @@ jobs:
id: latest_version
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
- name: Build
uses: goreleaser/goreleaser-action@v3
with:
Expand Down Expand Up @@ -103,9 +100,9 @@ jobs:
id: latest_version
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
owner: ${{ github.repository_owner }}
repo: watermarkpodautoscaler
excludes: prerelease, draft
- name: Build
uses: goreleaser/goreleaser-action@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ tags
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
.idea/
/bundle/tests/
*.bak
15 changes: 11 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
image: registry.ddbuild.io/images/mirror/golang:1.19-bullseye
image: registry.ddbuild.io/images/mirror/golang:1.21
variables:
GO111MODULE: "on"
PROJECTNAME: "watermarkpodautoscaler"
Expand Down Expand Up @@ -28,23 +28,30 @@ before_script:

build:
stage: build
tags: ["runner:main", "size:large"]
tags: ["arch:amd64"]
script:
- make build

tests:
stage: test
tags: ["runner:main", "size:large"]
tags: ["arch:amd64"]
script:
- make test

generate_code:
stage: test
tags: ["runner:main", "size:large"]
tags: ["arch:amd64"]
script:
- make generate
- git diff --exit-code

check-golang-version:
stage: test
tags: ["arch:amd64"]
script:
- make update-golang
- git diff --exit-code

build_image:
stage: image
tags:
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ bundle: manifests
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

# Update the golang version in different repository files from the version present in go.mod file
.PHONY: update-golang
update-golang:
hack/update-golang.sh

#
# Datadog Custom part
#
.PHONY: install-tools
install-tools: bin/$(PLATFORM)/golangci-lint bin/$(PLATFORM)/operator-sdk bin/$(PLATFORM)/yq bin/$(PLATFORM)/kubebuilder bin/$(PLATFORM)/kubebuilder-tools bin/$(PLATFORM)/go-licenses bin/$(PLATFORM)/openapi-gen bin/$(PLATFORM)/controller-gen bin/$(PLATFORM)/openapi-gen bin/$(PLATFORM)/kustomize
install-tools: bin/$(PLATFORM)/golangci-lint bin/$(PLATFORM)/operator-sdk bin/$(PLATFORM)/yq bin/$(PLATFORM)/jq bin/$(PLATFORM)/kubebuilder bin/$(PLATFORM)/kubebuilder-tools bin/$(PLATFORM)/go-licenses bin/$(PLATFORM)/openapi-gen bin/$(PLATFORM)/controller-gen bin/$(PLATFORM)/openapi-gen bin/$(PLATFORM)/kustomize

.PHONY: generate-openapi
generate-openapi: bin/$(PLATFORM)/openapi-gen
Expand Down Expand Up @@ -205,6 +210,9 @@ tidy:
bin/$(PLATFORM)/yq: Makefile
hack/install-yq.sh "bin/$(PLATFORM)" v4.31.2

bin/$(PLATFORM)/jq: Makefile
hack/install-jq.sh "bin/$(PLATFORM)" 1.7.1

bin/$(PLATFORM)/golangci-lint: Makefile
hack/install-golangci-lint.sh -b "bin/$(PLATFORM)" v1.56.0

Expand Down
35 changes: 35 additions & 0 deletions hack/install-jq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPTS_DIR="$(dirname "$0")"
# Provides $OS,$ARCH,$PLATFORM,$ROOT variables
source "$SCRIPTS_DIR/install-common.sh"



INSTALL_PATH=$1
VERSION=$2

BIN_ARCH=$(uname_arch)
OS=$(uname| tr [:upper:] [:lower:])
if [ "$OS" == "darwin" ]; then
OS="macos"
fi
BINARY="jq-$OS-$BIN_ARCH"

if [ -z "$VERSION" ];
then
echo "usage: bin/install-yq.sh <version>"
exit 1
fi

cd $WORK_DIR
# https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-arm64
curl -Lo ${BINARY} https://github.com/jqlang/jq/releases/download/jq-$VERSION/$BINARY

chmod +x $BINARY
mkdir -p $ROOT/$INSTALL_PATH/
mv $BINARY $ROOT/$INSTALL_PATH/jq
5 changes: 0 additions & 5 deletions hack/install-yq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ SCRIPTS_DIR="$(dirname "$0")"
# Provides $OS,$ARCH,$PLATFORM,$ROOT variables
source "$SCRIPTS_DIR/install-common.sh"

cleanup() {
rm -rf "$WORK_DIR"
}
trap "cleanup" EXIT SIGINT

INSTALL_PATH=$1
VERSION=$2

Expand Down
13 changes: 0 additions & 13 deletions hack/install_golang.sh

This file was deleted.

Loading

0 comments on commit 272d0da

Please sign in to comment.