Skip to content

Commit

Permalink
Merge pull request #2 from defenseunicorns/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
corang authored Oct 3, 2024
2 parents e1c312a + 43b5b0e commit b94a98e
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 142 deletions.
9 changes: 9 additions & 0 deletions .github/actions/golang/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: setup-go
description: "Setup Go binary and caching"

runs:
using: composite
steps:
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
21 changes: 21 additions & 0 deletions .github/actions/install-uds-cli/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Install UDS CLI
description: installs uds-cli


inputs:
udsCliVersion:
description: The uds-cli version to install
# renovate: datasource=github-tags depName=defenseunicorns/uds-cli versioning=semver
default: 0.16.0

runs:
using: composite
steps:
- name: Set UDS CLI Arch
id: setUdsCliArch
shell: bash
run: INPUT=${{ runner.arch == 'X64' && 'amd64' || runner.arch }}; echo "ARCH=${INPUT,,}" >> "$GITHUB_OUTPUT"

- name: Install UDS CLI
shell: bash
run: curl -o /usr/local/bin/uds -L https://github.com/defenseunicorns/uds-cli/releases/download/v${{ inputs.udsCliVersion }}/uds-cli_v${{ inputs.udsCliVersion }}_Linux_${{steps.setUdsCliArch.outputs.ARCH}} && chmod +x /usr/local/bin/uds
6 changes: 6 additions & 0 deletions .github/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
paths-ignore:
- build/**

query-filters:
- exclude:
id: go/path-injection
13 changes: 2 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ jobs:
with:
fetch-depth: 0

- name: Free up disk space
run: rm -rf /opt/hostedtoolcache

- name: Setup golang
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.21.x
uses: ./.github/actions/golang

- name: Install syft
uses: anchore/sbom-action/download-syft@61119d458adab75f756bc0b9e4bde25725f86a7a # v0.17.2

- name: Install grype
run: "curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin"
shell: bash

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
with:
distribution: goreleaser
version: latest
args: release --clean --verbose --config .goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}}
62 changes: 62 additions & 0 deletions .github/workflows/scan-codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Analyze CodeQL

permissions:
contents: read

on:
push:
branches: ["main"]
pull_request:
paths-ignore:
- "**.md"
- "**.jpg"
- "**.png"
- "**.gif"
- "**.svg"
- "adr/**"
- "docs/**"
- "CODEOWNERS"
- "goreleaser.yml"
schedule:
- cron: "32 2 * * 5"

jobs:
validate:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["go"]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup golang
uses: ./.github/actions/golang

- name: Install UDS CLI
uses: ./.github/actions/install-uds-cli

- name: Build UDS CLI
run: uds run build-cli-linux-amd

- name: Initialize CodeQL
uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
env:
CODEQL_EXTRACTOR_GO_BUILD_TRACING: on
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql.yaml


- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ go.work.sum

# build artifacts
build/
uds-releaser
uds-releaser
37 changes: 1 addition & 36 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,11 @@ snapshot:
changelog:
use: github-native

# brews:
# - name: uds
# repository:
# owner: defenseunicorns
# name: homebrew-tap
# token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
# branch: "{{ .ProjectName }}-{{ .Tag }}"
# pull_request:
# enabled: true
# base:
# branch: main
# owner: defenseunicorns
# name: homebrew-tap
# commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}"
# homepage: "https://github.com/defenseunicorns/uds-cli"
# description: "CLI for Unicorn Delivery Service"

# # NOTE: We are using .Version instead of .Tag because homebrew has weird semver parsing rules and won't be able to
# # install versioned releases that has a `v` character before the version number.
# - name: "uds@{{ .Version }}"
# repository:
# owner: defenseunicorns
# name: homebrew-tap
# token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
# branch: "{{ .ProjectName }}-{{ .Tag }}"
# pull_request:
# enabled: true
# base:
# branch: main
# owner: defenseunicorns
# name: homebrew-tap
# commit_msg_template: "Brew formula update for {{ .ProjectName }} versioned release {{ .Tag }}"
# homepage: "https://github.com/defenseunicorns/uds-cli"
# description: "CLI for Unicorn Delivery Service"

# Generate a GitHub release and publish the release for the tag
release:
github:
owner: defenseunicorns
name: uds-releaser
prerelease: auto
mode: append
draft: false
draft: false
19 changes: 19 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": [
"github>defenseunicorns/uds-common//config/renovate.json5",
":semanticCommits",
":semanticPrefixFixDepsChoreOthers",
"group:all",
"replacements:all",
"workarounds:all"
],
"schedule": ["after 7am and before 9am every weekday"],
"packageRules": [
{
"groupName": "UDS Releaser Support Dependencies",
"labels": ["support-deps"],
"commitMessageTopic": "support-deps",
"packagePatterns": ["*"]
}
]
}
10 changes: 0 additions & 10 deletions src/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,4 @@ var checkCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(checkCmd)

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

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

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// gitlabCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
16 changes: 1 addition & 15 deletions src/cmd/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,11 @@ var releaseCmd = &cobra.Command{

rootCmd.SilenceUsage = true

err = gitlab.TagAndRelease(currentFlavor)
if err != nil {
return err
}
return nil
return gitlab.TagAndRelease(currentFlavor)
},
}

func init() {
rootCmd.AddCommand(gitlabCmd)
gitlabCmd.AddCommand(releaseCmd)

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

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

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// gitlabCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
16 changes: 1 addition & 15 deletions src/cmd/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,10 @@ var mutateCmd = &cobra.Command{

rootCmd.SilenceUsage = true

err = version.MutateYamls(currentFlavor)
if err != nil {
return err
}
return nil
return version.MutateYamls(currentFlavor)
},
}

func init() {
rootCmd.AddCommand(mutateCmd)

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

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

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// gitlabCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
33 changes: 7 additions & 26 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -21,21 +21,14 @@ import (
"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "uds-releaser",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Short: "UDS Releaser is a tool for releasing UDS packages",
Long: `UDS Releaser is a tool that facilitates the release
of UDS packages. It provides commands for checking if a release is necessary,
mutating version fields in the zarf.yaml and uds-bundle.yaml files, and creating tags
and releases.`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -47,16 +40,4 @@ func Execute() {
}
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.uds-releaser.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


func init() {}
2 changes: 1 addition & 1 deletion src/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ type Flavor struct {

type ReleaserConfig struct {
Flavors []Flavor `yaml:"flavors"`
}
}
13 changes: 3 additions & 10 deletions src/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ func DoesTagExist(tag string) (bool, error) {
}
return nil
})
if err != nil {
return tagExists, err
}
return tagExists, nil
return tagExists, err
}

func OpenRepo() (*git.Repository, error) {
repo, err := git.PlainOpen(".")
if err != nil {
return nil, err
}
return repo, nil
}
return git.PlainOpen(".")
}
12 changes: 2 additions & 10 deletions src/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ func LoadYaml(path string, destVar interface{}) error {
return err
}

err = goyaml.Unmarshal(data, destVar)
if err != nil {
return err
}
return nil
return goyaml.Unmarshal(data, destVar)
}

func UpdateYaml(path string, srcVar interface{}) error {
Expand All @@ -42,9 +38,5 @@ func UpdateYaml(path string, srcVar interface{}) error {
return err
}

err = os.WriteFile(path, data, yamlInfo.Mode())
if err != nil {
return err
}
return nil
return os.WriteFile(path, data, yamlInfo.Mode())
}
2 changes: 1 addition & 1 deletion src/utils/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ func GetPackageName() (string, error) {
}

return zarfPackage.Metadata.Name, nil
}
}
Loading

0 comments on commit b94a98e

Please sign in to comment.