Skip to content

Commit

Permalink
chore: Add bump go script (#78)
Browse files Browse the repository at this point in the history
* chore: Add bump go script

* ci: Decrease matrix
  • Loading branch information
obalunenko authored Aug 22, 2023
1 parent c3a5f3f commit d28d2ea
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# Learn more about CodeQL language support at https://git.io/codeql-language-support
language: [ 'go' ]
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}
- run: |
go version
shell: bash
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
max-parallel: 3
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Build
steps:
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
max-parallel: 2
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Run Tests
steps:
Expand All @@ -102,7 +102,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
max-parallel: 2
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Run linters
steps:
Expand All @@ -149,7 +149,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}
- run: |
go version
shell: bash
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
max-parallel: 1
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Quality reports
steps:
Expand All @@ -201,7 +201,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}
- run: |
go version
shell: bash
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
max-parallel: 2
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Build
steps:
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
max-parallel: 2
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Regression tests
steps:
Expand All @@ -72,7 +72,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
max-parallel: 1
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Lint
steps:
Expand All @@ -121,7 +121,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
max-parallel: 1
matrix:
os: [ 'ubuntu-22.04' ]
go: [ '1.21' ]
go-version: [1.21.x]
runs-on: ${{ matrix.os }}
name: Release
steps:
Expand All @@ -174,7 +174,7 @@ jobs:
- name: Set up go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- run: |
go version
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ COMPOSE_TOOLS_CMD_BASE=docker compose -f $(COMPOSE_TOOLS_FILE)
COMPOSE_TOOLS_CMD_UP=$(COMPOSE_TOOLS_CMD_BASE) up --remove-orphans --exit-code-from
COMPOSE_TOOLS_CMD_PULL=$(COMPOSE_TOOLS_CMD_BASE) build

GOVERSION:=1.21

TARGET_MAX_CHAR_NUM=20

## Show help
Expand Down Expand Up @@ -147,5 +149,9 @@ new-version: vet test-regression build
./scripts/release/new-version.sh
.PHONY: new-release

bump-go-version:
./scripts/bump-go.sh $(GOVERSION)
.PHONY: bump-go-version

.DEFAULT_GOAL := help

71 changes: 71 additions & 0 deletions scripts/bump-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
readonly ROOT_DIR="$(dirname "$CURRENT_DIR")"
readonly GO_MOD_FILE="${ROOT_DIR}/go.mod"

function main() {
echo "Updating Go version:"

local currentGoVersion="$(extractCurrentVersion)"
echo " - Current: ${currentGoVersion}"
local escapedCurrentGoVersion="$(echo "${currentGoVersion}" | sed 's/\./\\./g')"

local goVersion="${1}"
local escapedGoVersion="$(echo "${goVersion}" | sed 's/\./\\./g')"
echo " - New: ${goVersion}"

# bump mod files in all the modules
for modFile in $(find "${ROOT_DIR}" -name "go.mod" -not -path "${ROOT_DIR}/vendor/*" -not -path "${ROOT_DIR}/.git/*"); do
bumpModFile "${modFile}" "${escapedCurrentGoVersion}" "${escapedGoVersion}"
done

# bump markdown files
for f in $(find "${ROOT_DIR}" -name "*.md"); do
bumpGolangDockerImages "${f}" "${escapedCurrentGoVersion}" "${escapedGoVersion}"
done

# bump github action workflows
for f in $(find "${ROOT_DIR}/.github/workflows" -name "*.yml"); do
bumpCIMatrix "${f}" "${escapedCurrentGoVersion}" "${escapedGoVersion}"
done
}

# it will replace the 'go-version: [${oldGoVersion}, 1.x]' with 'go-version: [${newGoVersion}, 1.x]' in the given file
function bumpCIMatrix() {
local file="${1}"
local oldGoVersion="${2}"
local newGoVersion="${3}"

sed "s/go-version: \[${oldGoVersion}/go-version: \[${newGoVersion}/g" ${file} > ${file}.tmp
mv ${file}.tmp ${file}
}

# it will replace the 'golang:${oldGoVersion}' with 'golang:${newGoVersion}' in the given file
function bumpGolangDockerImages() {
local file="${1}"
local oldGoVersion="${2}"
local newGoVersion="${3}"

sed "s/golang:${oldGoVersion}/golang:${newGoVersion}/g" ${file} > ${file}.tmp
mv ${file}.tmp ${file}

}

# it will replace the 'go ${oldGoVersion}' with 'go ${newGoVersion}' in the given go.mod file
function bumpModFile() {
local goModFile="${1}"
local oldGoVersion="${2}"
local newGoVersion="${3}"

sed "s/^go ${oldGoVersion}/go ${newGoVersion}/g" ${goModFile} > ${goModFile}.tmp
mv ${goModFile}.tmp ${goModFile}

}

# This function reads the reaper.go file and extracts the current version.
function extractCurrentVersion() {
cat "${GO_MOD_FILE}" | grep '^go .*' | sed 's/^go //g' | head -n 1
}

main "$@"

0 comments on commit d28d2ea

Please sign in to comment.