Skip to content

Commit eb9c7fa

Browse files
fix: upgrade to Go 1.26 (#232)
* fix: upgrade to Go 1.26 * ci: update github actions
1 parent fc76fc2 commit eb9c7fa

14 files changed

Lines changed: 331 additions & 160 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- cron: '0 10 * * 0'
1111

1212
env:
13-
GO_VERSION: '1.24'
13+
GO_VERSION: '1.26'
1414

1515
jobs:
1616
analyze:
@@ -67,7 +67,7 @@ jobs:
6767
uses: github/codeql-action/analyze@v4
6868

6969
- name: Upload CodeQL results
70-
uses: actions/upload-artifact@v5.0.0
70+
uses: actions/upload-artifact@v6.0.0
7171
with:
7272
name: codeql-results
7373
path: /home/runner/work/go-lambda-cleanup/results/go.sarif

.github/workflows/nightly.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ jobs:
3333
run: |
3434
aws ec2 describe-regions --all-regions --region us-east-1 --query "Regions[].RegionName" --output text >> cmd/aws-regions.txt
3535
36+
- name: Install Task
37+
uses: go-task/setup-task@v1
38+
3639
- name: Update Dependencies
3740
run: go get -u ./...
3841

3942
- name: Execute Go tests
40-
run: make tests
43+
run: task tests
4144

4245
- name: Set up QEMU
4346
uses: docker/setup-qemu-action@v3.7.0

.github/workflows/pull_request.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
packages: write
1111

1212
env:
13-
GO_VERSION: '1.24'
13+
GO_VERSION: '1.26'
1414

1515
jobs:
1616

@@ -41,7 +41,8 @@ jobs:
4141

4242
- name: Check out code into the Go module directory
4343
uses: actions/checkout@v6
44-
44+
- name: Install Task
45+
uses: go-task/setup-task@v1
4546

4647
- name: Generate AWS region file
4748
env:
@@ -56,10 +57,10 @@ jobs:
5657
# args: -v
5758

5859
- name: Execute Go tests
59-
run: make tests-coverage
60+
run: task tests-coverage
6061

6162
- name: Codecov Upload
62-
uses: codecov/codecov-action@v5.5.1
63+
uses: codecov/codecov-action@v5.5.2
6364
env:
6465
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6566

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ env:
88
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
1010
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11-
GO_VERSION: '1.24'
12-
UPX_VERSION: "4.2.4"
13-
SVU_VERSION: "2.0.1"
11+
GO_VERSION: '1.26'
12+
UPX_VERSION: "5.1.0"
13+
SVU_VERSION: "3.3.0"
1414

1515
jobs:
1616
tag:

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77

88
env:
9-
GO_VERSION: '1.24'
9+
GO_VERSION: '1.26'
1010

1111
jobs:
1212
test:
@@ -24,6 +24,9 @@ jobs:
2424
- name: Check out code into the Go module directory
2525
uses: actions/checkout@v6
2626

27+
- name: Install Task
28+
uses: go-task/setup-task@v1
29+
2730
- name: Generate AWS region file
2831
env:
2932
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -37,7 +40,7 @@ jobs:
3740
# args: -v
3841

3942
- name: Execute Go tests
40-
run: make tests-coverage
43+
run: task tests-coverage
4144

4245
- name: Test CLI
4346
env:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) karl-cardenas-coding
22
# SPDX-License-Identifier: MIT
33

4-
FROM golang:1.24.2-alpine3.21 AS builder
4+
FROM golang:1.26.0-alpine3.22 AS builder
55

66
LABEL org.opencontainers.image.source="http://github.com/karl-cardenas-coding/go-lambda-cleanup"
77
LABEL org.opencontainers.image.description="A solution for removing previous versions of AWS Lambdas"

Taskfile.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://taskfile.dev
2+
version: '3'
3+
4+
tasks:
5+
aws-regions:
6+
desc: Generate AWS regions file
7+
cmds:
8+
- aws ec2 describe-regions --region us-east-1 --all-regions --query "Regions[].RegionName" --output text > cmd/aws-regions.txt
9+
10+
license:
11+
desc: Apply license headers
12+
cmds:
13+
- copywrite headers
14+
15+
opensource:
16+
desc: Check open source licenses
17+
cmds:
18+
- ~/go/bin/go-licenses report github.com/karl-cardenas-coding/go-lambda-cleanup/v2 --template=documentation/open-source.tpl > documentation/open-source.md
19+
20+
lint:
21+
desc: Run Go linter
22+
cmds:
23+
- golangci-lint run ./...
24+
25+
build:
26+
desc: Build the binary
27+
cmds:
28+
- go build -ldflags="-X 'github.com/karl-cardenas-coding/go-lambda-cleanup/v2/cmd.VersionString=1.0.0'" -o=glc -v
29+
30+
tests:
31+
desc: Run tests
32+
cmds:
33+
- go test -shuffle on -race ./...
34+
35+
tests-coverage:
36+
desc: Run tests with code coverage
37+
cmds:
38+
- go test -race -shuffle on -cover -coverprofile=coverage.out -covermode=atomic ./...
39+
40+
view-coverage:
41+
desc: View code coverage report
42+
cmds:
43+
- go tool cover -html=coverage.out
44+
45+
nil:
46+
desc: Check for nil errors
47+
cmds:
48+
- ~/go/bin/nilaway ./...

cmd/clean.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ var cleanCmd = &cobra.Command{
6161
config = GlobalCliConfig
6262
awsEnvRegion = os.Getenv("AWS_DEFAULT_REGION")
6363
awsEnvProfile = os.Getenv("AWS_PROFILE")
64+
6465
if *config.RegionFlag == "" {
6566
if awsEnvRegion != "" {
6667
*config.RegionFlag, err = validateRegion(f, awsEnvRegion)
6768
if err != nil {
6869
return err
6970
}
70-
7171
} else {
7272
return errors.New("missing region flag and AWS_DEFAULT_REGION env variable. Please use -r and provide a valid AWS region")
7373
}
@@ -94,6 +94,7 @@ var cleanCmd = &cobra.Command{
9494
} else {
9595
log.Infof("The AWS Profile flag \"%s\" was passed in", *config.ProfileFlag)
9696
}
97+
9798
awsConfigOptions = append(awsConfigOptions, awsConfig.WithSharedConfigProfile(*config.ProfileFlag))
9899

99100
if *config.Verbose {
@@ -112,11 +113,13 @@ var cleanCmd = &cobra.Command{
112113

113114
if *config.LambdaListFile != "" {
114115
log.Info("******** CUSTOM LAMBDA LIST PROVIDED ********")
116+
115117
list, err := internal.GenerateLambdaDeleteList(*config.LambdaListFile)
116118
if err != nil {
117119
log.Infof("an issue occurred while processing %s", *config.LambdaListFile)
118120
log.Info(err.Error())
119121
}
122+
120123
customeDeleteList = list
121124
}
122125

@@ -129,6 +132,7 @@ var cleanCmd = &cobra.Command{
129132
if err != nil {
130133
return errors.New("ERROR RETRIEVING AWS CREDENTIALS")
131134
}
135+
132136
if creds.Expired() {
133137
return errors.New("AWS CREDENTIALS EXPIRED")
134138
}
@@ -138,6 +142,7 @@ var cleanCmd = &cobra.Command{
138142
// Set the User-Agent for all AWS with the Lambda client
139143
o.APIOptions = append(o.APIOptions, middleware.AddUserAgentKeyValue("go-lambda-cleanup", VersionString))
140144
})
145+
141146
err = executeClean(ctx, &config, initSvc, customeDeleteList)
142147
if err != nil {
143148
return err
@@ -150,7 +155,7 @@ var cleanCmd = &cobra.Command{
150155
/*
151156
executeClean is the main function that executes the clean-up process
152157
It takes a context, a pointer to a cliConfig struct, a pointer to a lambda client, and a list of custom lambdas to delete
153-
An error is returned if the function fails to execute
158+
An error is returned if the function fails to execute.
154159
*/
155160
func executeClean(ctx context.Context, config *cliConfig, svc *lambda.Client, customList []string) error {
156161
startTime := time.Now()
@@ -311,7 +316,7 @@ func displayDuration(startTime time.Time) {
311316
}
312317

313318
// generateDeleteInputStructs takes a list of lambda.DeleteFunctionInput and a boolean value to determine if the user wants more details. The function returns a list of lambda.DeleteFunctionInput
314-
// An error is returned if the function fails to execute
319+
// An error is returned if the function fails to execute.
315320
func generateDeleteInputStructs(versionsList [][]types.FunctionConfiguration, details bool) ([][]lambda.DeleteFunctionInput, error) {
316321
var (
317322
returnError error
@@ -349,7 +354,7 @@ func generateDeleteInputStructs(versionsList [][]types.FunctionConfiguration, de
349354
}
350355

351356
// calculateSpaceRemoval returns the total size of all the versions to be deleted.
352-
// The function takes a list of lambda.DeleteFunctionInput and returns an int
357+
// The function takes a list of lambda.DeleteFunctionInput and returns an int.
353358
func calculateSpaceRemoval(deleteList [][]types.FunctionConfiguration) int {
354359
var (
355360
size int
@@ -367,7 +372,7 @@ func calculateSpaceRemoval(deleteList [][]types.FunctionConfiguration) int {
367372
}
368373

369374
// countDeleteVersions returns the total number of versions to be deleted.
370-
// The function takes a list of lambda.DeleteFunctionInput and returns an int
375+
// The function takes a list of lambda.DeleteFunctionInput and returns an int.
371376
func countDeleteVersions(deleteList [][]lambda.DeleteFunctionInput) int {
372377
var (
373378
versionsCount int
@@ -594,16 +599,16 @@ func getLambdaStorage(list []types.FunctionConfiguration) (int64, error) {
594599

595600
// validateRegion validates the user input to ensure it is a valid AWS region. The function takes a embed.FS and a string. The function returns a string and an error
596601
// An embedded file is used to validate the user input. The embedded file contains a list of all the AWS regions
597-
// Example of the embedded file: ap-south-2 ap-south-1 eu-south-1 eu-south-2 me-central-1 ca-central-1 eu-central-1 eu-central-2
602+
// Example of the embedded file: ap-south-2 ap-south-1 eu-south-1 eu-south-2 me-central-1 ca-central-1 eu-central-1 eu-central-2.
598603
func validateRegion(f embed.FS, input string) (string, error) {
599604
var output string
600605

601606
var err error
602607

603608
rawData, _ := f.ReadFile(regionFile)
604-
regionsList := strings.Split(string(rawData), " ")
609+
regionsList := strings.SplitSeq(string(rawData), " ")
605610

606-
for _, region := range regionsList {
611+
for region := range regionsList {
607612
if strings.ToLower(input) == strings.TrimSpace(region) {
608613
output = strings.TrimSpace(region)
609614
}

0 commit comments

Comments
 (0)