Skip to content

Commit

Permalink
feat: migrate to golang (#63)
Browse files Browse the repository at this point in the history
* feat: migrate to golang

* chore(main): release 1.7.0 (#59)

* feat: migrate to golang

* remove unused old files

* chore(main): release 1.7.0 (#59)

* chore: update test workflow

* chore: update github action for go build
  • Loading branch information
y3owk1n authored Dec 3, 2024
1 parent 383b542 commit 7eed464
Show file tree
Hide file tree
Showing 40 changed files with 1,013 additions and 2,016 deletions.
36 changes: 7 additions & 29 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,29 @@ jobs:
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
# this is a built-in strategy in release-please, see "Action Inputs"
# for more options
release-type: node
release-type: go

- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}

- name: Install Just
if: ${{ steps.release.outputs.release_created }}
uses: extractions/setup-just@v1

- uses: pnpm/action-setup@v4
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v4
if: ${{ steps.release.outputs.release_created }}
with:
node-version: 22
cache: "pnpm"

- uses: oven-sh/setup-bun@v2
- uses: actions/setup-go@v5
if: ${{ steps.release.outputs.release_created }}
with:
bun-version: 1.1.34

- uses: actions/cache@v4
if: ${{ steps.release.outputs.release_created }}
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- shell: bash
if: ${{ steps.release.outputs.release_created }}
run: pnpm install
go-version: "^1.23.3"

- name: Build project and prepare release artifact
if: ${{ steps.release.outputs.release_created }}
run: just compile
run: |
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X cpenv/cmd.Version=${{ steps.release.outputs.tag_name }}" -o ./compile/cpenv-darwin-arm64 ./main.go
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X cpenv/cmd.Version=${{ steps.release.outputs.tag_name }}" -o ./compile/cpenv-darwin-amd64 ./main.go
- name: Upload Release Artifact
if: ${{ steps.release.outputs.release_created }}
env:
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
run: |
gh release upload ${{ steps.release.outputs.tag_name }} ./compile/cpenv-darwin-arm64
gh release upload ${{ steps.release.outputs.tag_name }} ./compile/cpenv-darwin-x64
gh release upload ${{ steps.release.outputs.tag_name }} ./compile/cpenv-darwin-amd64
72 changes: 72 additions & 0 deletions .github/workflows/release-please.yml.bak2
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
# this assumes that you have created a personal access token
# (PAT) and configured it as a GitHub action secret named
# `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important).
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
# this is a built-in strategy in release-please, see "Action Inputs"
# for more options
release-type: node

- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}

- name: Install Just
if: ${{ steps.release.outputs.release_created }}
uses: extractions/setup-just@v1

- uses: pnpm/action-setup@v4
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v4
if: ${{ steps.release.outputs.release_created }}
with:
node-version: 22
cache: "pnpm"

- uses: oven-sh/setup-bun@v2
if: ${{ steps.release.outputs.release_created }}
with:
bun-version: 1.1.34

- uses: actions/cache@v4
if: ${{ steps.release.outputs.release_created }}
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-

- shell: bash
if: ${{ steps.release.outputs.release_created }}
run: pnpm install

- name: Build project and prepare release artifact
if: ${{ steps.release.outputs.release_created }}
run: just compile

- name: Upload Release Artifact
if: ${{ steps.release.outputs.release_created }}
env:
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
run: |
gh release upload ${{ steps.release.outputs.tag_name }} ./compile/cpenv-darwin-arm64
gh release upload ${{ steps.release.outputs.tag_name }} ./compile/cpenv-darwin-x64
27 changes: 5 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,11 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}

- name: Install Just
uses: extractions/setup-just@v1

- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

- uses: oven-sh/setup-bun@v2
- uses: actions/setup-go@v5
with:
bun-version: 1.1.34

- uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- shell: bash
run: pnpm install
go-version: "^1.23.3"

- name: Build project and prepare release artifact
run: just compile
run: |
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X cpenv/cmd.Version=${{ steps.release.outputs.tag_name }}" -o ./compile/cpenv-darwin-arm64 ./main.go
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X cpenv/cmd.Version=${{ steps.release.outputs.tag_name }}" -o ./compile/cpenv-darwin-amd64 ./main.go
42 changes: 42 additions & 0 deletions .github/workflows/test.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
pull_request:
branches: ["*"]
tags-ignore:
- "release-please--*" # Exclude tags containing "staging"

name: test build

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}

- name: Install Just
uses: extractions/setup-just@v1

- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.34

- uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-

- shell: bash
run: pnpm install

- name: Build project and prepare release artifact
run: just compile
10 changes: 0 additions & 10 deletions Justfile

This file was deleted.

38 changes: 0 additions & 38 deletions biome.json

This file was deleted.

61 changes: 61 additions & 0 deletions cmd/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"cpenv/core"
"cpenv/utils"
"fmt"

"github.com/spf13/cobra"
)

// backupCmd represents the backup command
var backupCmd = &cobra.Command{
Use: "backup",
Short: "Backup current project env(s) to vault",
Run: func(cmd *cobra.Command, args []string) {
config, err := core.LoadConfig()
if err != nil {
utils.Logger.Debug("Failed to load config", "message", err)
fmt.Println(utils.ErrorMessage.Render("Please run `cpenv config init`"))
return
}

utils.Logger.Debug("Running backupCmd", "Vault Directory", config.VaultDir)

_, err = core.CreateEnvFilesDirectoryIfNotFound(config.VaultDir)
if err != nil {
utils.Logger.Error("Failed to create env file directory", "message", err)
return
}

err = core.ConfirmCwd()
if err != nil {
utils.Logger.Error("Failed to confirm cwd", "message", err)
return
}

err = core.CopyEnvFilesToVault()
if err != nil {
utils.Logger.Error("Failed to copy env files to vault", "message", err)
return
}
fmt.Println(utils.SuccessMessage.Render(" Copy completed successfully"))
},
}

func init() {
rootCmd.AddCommand(backupCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// backupCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// backupCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
76 changes: 76 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"cpenv/core"
"cpenv/utils"
"fmt"
"os"

"github.com/spf13/cobra"
)

// configCmd represents the init command
var configCmd = &cobra.Command{
Use: "config",
Short: "Config management for cpenv",
}

var configInitCmd = &cobra.Command{
Use: "init",
Short: "Initialize a config for cpenv to work",
Run: func(cmd *cobra.Command, args []string) {
_, err := core.LoadConfig()
if err != nil {
toInitConfig := &core.Config{VaultDir: ".env-files"}

err := core.SaveConfig(toInitConfig)
if err != nil {
utils.Logger.Error("Failed to save config", "message", err)
os.Exit(1)
}

fmt.Println(utils.SuccessMessage.Render(" Configuration initialized successfully!"))
} else {
fmt.Println(utils.ErrorMessage.Render("Configuration exists! Use `cpenv config edit` to edit it"))
}
},
}

var configEditCmd = &cobra.Command{
Use: "edit",
Short: "Edit the cpenv config with $EDITOR",
Run: func(cmd *cobra.Command, args []string) {
_, err := core.LoadConfig()
if err != nil {
utils.Logger.Debug("Failed to load config", "message", err)
fmt.Println(utils.ErrorMessage.Render("Please run `cpenv config init`"))
return
}

if err := utils.OpenInEditor(core.ConfigPath); err != nil {
utils.Logger.Error("Failed to open the file in editor", "message", err)
} else {
fmt.Println(utils.SuccessMessage.Render(" Successfully opened the file in editor."))
}
},
}

func init() {
rootCmd.AddCommand(configCmd)

configCmd.AddCommand(configInitCmd)
configCmd.AddCommand(configEditCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// initCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
Loading

0 comments on commit 7eed464

Please sign in to comment.