Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use justfile vs. makefile #84

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]
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/[email protected]

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
Loading