Skip to content

Commit

Permalink
chore(maintenance): bump Go and GitHub Action versions
Browse files Browse the repository at this point in the history
And switch to `golangci-lint` linter.

Signed-off-by: peterdeme <[email protected]>
  • Loading branch information
peterdeme committed Oct 19, 2023
1 parent 5347077 commit 8ac871b
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 191 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push: { branches: [main] }
pull_request: { branches: [main] }

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
name: Lint the code
Expand All @@ -12,7 +16,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Mark source directory as safe.
run: git config --global --add safe.directory $GITHUB_WORKSPACE
Expand All @@ -23,8 +27,8 @@ jobs:
- name: Check for suspicious constructs using "go vet"
run: go vet ./...

- name: Lint the code using "golint"
run: go install golang.org/x/lint/golint@latest && golint -set_exit_status ./...

- name: Run staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest && staticcheck ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --verbose
18 changes: 11 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: 🚀 Release

on: { push }

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
goreleaser:
name: Release
Expand All @@ -14,28 +18,28 @@ jobs:
steps:
- name: Generate winget token
id: winget_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.WINGET_APP_ID }}
private_key: ${{ secrets.WINGET_APP_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { fetch-depth: 0 }

- name: Set up Go
uses: actions/setup-go@v4
with: { go-version: 1.21 }

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with: { platforms: linux/arm64 }

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
registry: ghcr.io
Expand All @@ -44,7 +48,7 @@ jobs:

- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
Expand All @@ -55,7 +59,7 @@ jobs:
gpg --armor --export ${{ steps.import_gpg.outputs.keyid }} > key.asc
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean --snapshot=${{ !startsWith(github.ref, 'refs/tags/v') }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ on:
schedule:
- cron: "19 7 * * 0"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest

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

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand All @@ -34,7 +38,7 @@ jobs:

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

- name: Run GoSec Security Scanner
uses: securego/gosec@master
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push: { branches: [main] }
pull_request: { branches: [main] }

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
unit-testing:
name: Test the code
Expand All @@ -13,15 +17,17 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Install dependencies
run: go mod download

- name: Test the code
- name: Run unit tests
run: go test ./...

- name: Test that the binary is executable
run: |
go build
./spacectl version
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ steps:
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
run: spacectl stack deploy --id my-infra-stack
```
---
### Community supported packages
**Disclaimer:** These packages are community-maintained, please verify the package integrity yourself before using them to install or update `spacectl`.
Expand Down Expand Up @@ -246,10 +248,11 @@ OPTIONS:

Each of the subcommands requires an account **alias**, which is a short, user-friendly name for each set of credentials (account profiles). Profiles don't need to be unique - you can have multiple sets of credentials for a single account too.

Account profiles support three authentication methods:
* GitHub access tokens
* API keys
* Login with a browser (API token).
Account profiles support three authentication methods:

- GitHub access tokens
- API keys
- Login with a browser (API token).

In order to authenticate to your first profile, type in the following (make sure to replace `${MY_ALIAS}` with the actual profile alias):

Expand Down
9 changes: 6 additions & 3 deletions client/session/from_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package session

import (
"context"
"github.com/franela/goblin"
"net/http"
"net/http/httptest"
"testing"

"github.com/franela/goblin"
)

// lookupWithEnv creates a custom lookup func which will return desired test values
Expand Down Expand Up @@ -49,7 +50,8 @@ func TestFromEnvironment(t *testing.T) {
g.It("expect EnvSpaceliftAPIToken to be used and EnvSpaceliftAPIKeyID and EnvSpaceliftAPIKeySecret to be ignored", func() {
// Create a mock http server to handle JWT exchange
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"data":{"apiKeyUser":{"jwt":"SuperSecretJWT","validUntil":123}}}`))
_, err := rw.Write([]byte(`{"data":{"apiKeyUser":{"jwt":"SuperSecretJWT","validUntil":123}}}`))
g.Assert(err).IsNil()
}))
// Close the server when test finishes
defer server.Close()
Expand All @@ -68,7 +70,8 @@ func TestFromEnvironment(t *testing.T) {
g.It("expect a CredentialsTypeAPIKey session to be created", func() {
// Create a mock http server to handle JWT exchange
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"data":{"apiKeyUser":{"jwt":"SuperSecretJWT","validUntil":123}}}`))
_, err := rw.Write([]byte(`{"data":{"apiKeyUser":{"jwt":"SuperSecretJWT","validUntil":123}}}`))
g.Assert(err).IsNil()
}))
// Close the server when test finishes
defer server.Close()
Expand Down
30 changes: 15 additions & 15 deletions client/session/profile_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ func TestProfileManager(t *testing.T) {
g.Describe("Get", func() {
g.It("can get a profile", func() {
profileAlias := "test-profile"
manager.Create(&session.Profile{
Expect(manager.Create(&session.Profile{
Alias: profileAlias,
Credentials: createValidGitHubCredentials(),
})
})).To(Succeed())

testProfile, err := manager.Get(profileAlias)

Expand All @@ -269,10 +269,10 @@ func TestProfileManager(t *testing.T) {

g.Describe("Select", func() {
g.It("can set the current profile", func() {
manager.Create(createValidProfile("profile1"))
manager.Create(createValidProfile("profile2"))
Expect(manager.Create(createValidProfile("profile1"))).To(Succeed())
Expect(manager.Create(createValidProfile("profile2"))).To(Succeed())

manager.Select("profile1")
Expect(manager.Select("profile1")).To(Succeed())

currentProfile := manager.Current()
Expect(currentProfile).NotTo(BeNil())
Expand All @@ -290,9 +290,9 @@ func TestProfileManager(t *testing.T) {

g.Describe("Delete", func() {
g.It("can delete a profile", func() {
manager.Create(createValidProfile("profile1"))
Expect(manager.Create(createValidProfile("profile1"))).To(Succeed())

manager.Delete("profile1")
Expect(manager.Delete("profile1")).To(Succeed())

profile, err := manager.Get("profile1")
Expect(err).To(BeNil())
Expand All @@ -312,19 +312,19 @@ func TestProfileManager(t *testing.T) {
})

g.It("unsets profile if it is the current profile", func() {
manager.Create(createValidProfile("profile1"))
Expect(manager.Create(createValidProfile("profile1"))).To(Succeed())

manager.Delete("profile1")
Expect(manager.Delete("profile1")).To(Succeed())

current := manager.Current()
Expect(current).To(BeNil())
})

g.It("does not unset profile if it is not the current profile", func() {
manager.Create(createValidProfile("profile1"))
manager.Create(createValidProfile("profile2"))
Expect(manager.Create(createValidProfile("profile1"))).To(Succeed())
Expect(manager.Create(createValidProfile("profile2"))).To(Succeed())

manager.Delete("profile1")
Expect(manager.Delete("profile1")).To(Succeed())

current := manager.Current()
Expect(current).NotTo(BeNil())
Expand All @@ -340,9 +340,9 @@ func TestProfileManager(t *testing.T) {
})

g.It("returns all profiles", func() {
manager.Create(createValidProfile("profile-1"))
manager.Create(createValidProfile("profile-2"))
manager.Create(createValidProfile("profile-3"))
Expect(manager.Create(createValidProfile("profile-1"))).To(Succeed())
Expect(manager.Create(createValidProfile("profile-2"))).To(Succeed())
Expect(manager.Create(createValidProfile("profile-3"))).To(Succeed())

profiles := manager.GetAll()

Expand Down
Loading

0 comments on commit 8ac871b

Please sign in to comment.