Skip to content

Commit

Permalink
feat: Use justfile vs. makefile
Browse files Browse the repository at this point in the history
- Cleans up and updates GitHub actions with new versions of actions
- Cleans up failing linter checks
- Upgrades Go dependencies

Signed-off-by: John McBride <john@opensauced.pizza>
  • Loading branch information
jpmcb committed Aug 26, 2024
1 parent 39823cd commit 8a7bc0d
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto-add-to-project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Adds all issues opened in the /pizza-cli repo to the Team Dashboard
name: "Adds issues to Team Dashboard"

on:
issues:
Expand All @@ -16,7 +16,7 @@ jobs:
with:
app_id: ${{ secrets.OS_GITHUB_APP_ID }}
private_key: ${{ secrets.OS_GITHUB_APP_PRIVATE_KEY }}

- name: add issue to team dashboard
uses: actions/add-to-project@v0.5.0
with:
Expand Down
79 changes: 58 additions & 21 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Semantic release
name: "Semantic release"

on:
push:
Expand All @@ -7,27 +7,37 @@ on:
- beta
workflow_dispatch:

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Test, lint, & build
uses: ./.github/workflows/test.yaml

release:
outputs:
release-tag: ${{ steps.semantic-release.outputs.release-tag }}
name: Semantic release
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OS_GITHUB_APP_ID }}
private_key: ${{ secrets.OS_GITHUB_APP_PRIVATE_KEY }}

- name: "☁️ checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}

- name: "🔧 setup node"
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand All @@ -36,47 +46,74 @@ jobs:

- name: "🚀 release"
id: semantic-release
uses: open-sauced/release@v2
env:
# This ensures that publishing happens on every single trigger which then
# forces the go binaries to be built in the next step and attached to the GitHub release
FORCE_PUBLISH: "patch"

GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_PACKAGE_ROOT: "npm"
uses: open-sauced/release@v2.2.1

outputs:
release-tag: ${{ steps.semantic-release.outputs.release-tag }}

build:
name: Build and publish artifacts
needs:
- release
if: needs.release.outputs.release-tag != ''
runs-on: ubuntu-latest
permissions:
contents: write # release changes require contents write
# release changes require contents write so that it can push Go binaries
contents: write
strategy:
matrix:
goos: [darwin, linux, windows]
goarch: [amd64, arm64]

steps:
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
- name: "☁️ checkout repository"
uses: actions/checkout@v4

- name: "🐹 Setup Go"
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Check out code
uses: actions/checkout@v3
- name: "🤲 Setup Just"
uses: extractions/setup-just@v2

- name: Build and upload Go binaries
- name: "🔧 Build all and upload artifacts to release"
env:
GH_TOKEN: ${{ github.token }}
run: |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${{ vars.POSTHOG_WRITE_PUBLIC_KEY }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${{ needs.release.outputs.release-tag }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-o build/pizza-${{ matrix.goos }}-${{ matrix.goarch }}
gh release upload ${{ needs.release.outputs.release-tag }} build/pizza-${{ matrix.goos }}-${{ matrix.goarch }}
export RELEASE_TAG_VERSION=${{ needs.release.outputs.release-tag }}
just build-${{ matrix.goos }}-${{ matrix.goarch }}
gh release upload ${{ needs.release.outputs.release-tag }} build/saucectl-${{ matrix.goos }}-${{ matrix.goarch }}
docker:
name: Build and push container
needs:
- release
if: needs.release.outputs.release-tag != ''
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v4

- name: "🔧 setup buildx"
uses: docker/setup-buildx-action@v3

- name: "🐳 Login to ghcr"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "📦 docker build and push"
uses: docker/build-push-action@v6
with:
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.release.outputs.release-tag }}
push: true
37 changes: 19 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Lint, test, and build
name: "Lint, test, and build"

on:
workflow_call:
push:
branches:
- main
Expand All @@ -12,41 +13,41 @@ on:
- reopened

permissions:

# So golangci-lint can read the contents of the lint yaml file
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: '1.22'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.2
version: v1.59.1

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: '1.22'
- uses: extractions/setup-just@v2
- name: Test
run: make test
run: just test

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Build go binary
run: make build
go-version: '1.22'
- uses: extractions/setup-just@v2
- name: Build Go binary
run: just build
12 changes: 11 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ linters:
- staticcheck
- unconvert
- unused
- vet
- govet
- gci

linters-settings:
gci:
sections:
# include the default standard section, default section, and the "local"
# section which can be configured with
# 'goimports -local github.com/open-sauced/saucectl'
- standard
- default
- localmodule

run:
timeout: 5m
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM --platform=$BUILDPLATFORM golang:1.22.5 AS builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG VERSION
ARG SHA

# Get the dependencies downloaded
WORKDIR /app
ENV CGO_ENABLED=0
COPY go.* ./
RUN go mod download
COPY . ./

# Build Go CLI binary
RUN go build -ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}'" \
-o pizza .

# Runner layer
FROM --platform=$BUILDPLATFORM golang:alpine
COPY --from=builder /app/pizza /usr/bin/
ENTRYPOINT ["/usr/bin/pizza"]
27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions cmd/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
"time"

"github.com/cli/browser"
"github.com/spf13/cobra"

"github.com/open-sauced/pizza-cli/pkg/constants"
"github.com/open-sauced/pizza-cli/pkg/utils"
"github.com/spf13/cobra"
)

//go:embed success.html
Expand All @@ -48,7 +49,7 @@ func NewLoginCommand() *cobra.Command {
Short: "Log into the CLI application via GitHub",
Long: loginLongDesc,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
username, err := run()

disableTelem, _ := cmd.Flags().GetBool(constants.FlagNameTelemetry)
Expand Down
5 changes: 3 additions & 2 deletions cmd/bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"sync"

"github.com/open-sauced/go-api/client"
"github.com/spf13/cobra"

"github.com/open-sauced/pizza-cli/pkg/api"
"github.com/open-sauced/pizza-cli/pkg/constants"
"github.com/open-sauced/pizza-cli/pkg/utils"
"github.com/spf13/cobra"
)

// Options are the options for the pizza bake command including user
Expand Down Expand Up @@ -55,7 +56,7 @@ func NewBakeCommand() *cobra.Command {
opts.Repos = append(opts.Repos, args...)
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
endpointURL, _ := cmd.Flags().GetString(constants.FlagNameEndpoint)
opts.APIClient = api.NewGoClient(endpointURL)
disableTelem, _ := cmd.Flags().GetBool(constants.FlagNameTelemetry)
Expand Down
5 changes: 3 additions & 2 deletions cmd/insights/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

bubblesTable "github.com/charmbracelet/bubbles/table"
"github.com/open-sauced/go-api/client"
"github.com/spf13/cobra"

"github.com/open-sauced/pizza-cli/pkg/api"
"github.com/open-sauced/pizza-cli/pkg/constants"
"github.com/open-sauced/pizza-cli/pkg/utils"
"github.com/spf13/cobra"
)

type contributorsOptions struct {
Expand Down Expand Up @@ -50,7 +51,7 @@ func NewContributorsCommand() *cobra.Command {
opts.Repos = append(opts.Repos, args...)
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
endpointURL, _ := cmd.Flags().GetString(constants.FlagNameEndpoint)
opts.APIClient = api.NewGoClient(endpointURL)
output, _ := cmd.Flags().GetString(constants.FlagNameOutput)
Expand Down
2 changes: 1 addition & 1 deletion cmd/insights/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func NewInsightsCommand() *cobra.Command {
Use: "insights <command> [flags]",
Short: "Gather insights about git contributors, repositories, users and pull requests",
Long: "Gather insights about git contributors, repositories, user and pull requests and display the results",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/insights/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

bubblesTable "github.com/charmbracelet/bubbles/table"
"github.com/open-sauced/go-api/client"
"github.com/spf13/cobra"

"github.com/open-sauced/pizza-cli/pkg/api"
"github.com/open-sauced/pizza-cli/pkg/constants"
"github.com/open-sauced/pizza-cli/pkg/utils"
"github.com/spf13/cobra"
)

type repositoriesOptions struct {
Expand Down Expand Up @@ -51,7 +52,7 @@ func NewRepositoriesCommand() *cobra.Command {
opts.Repos = append(opts.Repos, args...)
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
endpointURL, _ := cmd.Flags().GetString(constants.FlagNameEndpoint)
opts.APIClient = api.NewGoClient(endpointURL)
output, _ := cmd.Flags().GetString(constants.FlagNameOutput)
Expand Down
Loading

0 comments on commit 8a7bc0d

Please sign in to comment.