Skip to content

Commit

Permalink
bump Go version to 1.21, test build succeeds, submit Go dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fquffio committed Nov 7, 2023
1 parent 64cf916 commit c1a1781
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20
go-version-file: go.mod

- name: Build
run: |
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/dependency-submisson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Go Dependency Submission"

on:
push:
branches: [ main ]

permissions:
contents: write


jobs:
go-action-detection:
name: Submit dependencies
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Run snapshot action
uses: actions/go-dependency-submission@v1
with:
go-mod-path: go.mod
go-build-target: main.go
31 changes: 23 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,35 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version-file: go.mod

- name: Linter
uses: golangci/golangci-lint-action@v3
with:
version: latest

# unit:
# strategy:
# matrix:
# os: [ ubuntu-latest, macOS-latest ]
build:
name: Test build succeeds
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

# name: Run unit tests on ${{ matrix.os }}
# runs-on: ${{ matrix.os }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Build
run: go build -v ./...

# unit:
# name: Run unit tests
# runs-on: ubuntu-latest
# timeout-minutes: 5

# steps:
Expand All @@ -42,7 +57,7 @@ jobs:
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: 1.18
# go-version-file: go.mod

# - name: Build
# run: go build -v ./...
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/chialab/aws-ecr-get-login-password

go 1.20
go 1.21

require (
github.com/aws/aws-sdk-go-v2/config v1.22.1
Expand Down
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@ import (
)

func main() {
if token, err := getToken(); err != nil {
log.Fatal(err)
} else {
fmt.Println(token)
}
}

// Retrieve token for authentication against ECR registries.
func getToken() (string, error) {
os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatal(err)
return "", err
}

svc := ecr.NewFromConfig(cfg)
token, err := svc.GetAuthorizationToken(context.TODO(), &ecr.GetAuthorizationTokenInput{})
if err != nil {
log.Fatal(err)
return "", err
}

authData := token.AuthorizationData[0].AuthorizationToken
data, err := base64.StdEncoding.DecodeString(*authData)
if err != nil {
log.Fatal(err)
return "", err
}

parts := strings.SplitN(string(data), ":", 2)
fmt.Println(parts[1])

return parts[1], nil
}

0 comments on commit c1a1781

Please sign in to comment.