From a6ff55ec85b9209a6080849643375d42c1e606a6 Mon Sep 17 00:00:00 2001 From: Marvin Drees Date: Mon, 27 Nov 2023 15:18:48 +0100 Subject: [PATCH] feat: initial commit --- .github/ISSUE_TEMPLATE/bug-report.yml | 57 +++++++ .github/ISSUE_TEMPLATE/config.yml | 8 + .github/workflows/build.yml | 36 ++++ .github/workflows/lint.yml | 30 ++++ .github/workflows/release.yml | 86 ++++++++++ .github/workflows/tests.yml | 72 ++++++++ .gitignore | 1 + .golangci.yml | 226 ++++++++++++++++++++++++++ .goreleaser.yml | 80 +++++++++ CODEOWNERS | 8 + CODE_OF_CONDUCT.md | 1 + CONTRIBUTING.md | 1 + LICENSE | 29 ++++ README.md | 51 ++++++ RELEASING.md | 1 + VERSIONING.md | 1 + ci/.gitignore | 1 + ci/README.md | 15 ++ ci/main.go | 70 ++++++++ cmd/example/main.go | 9 + cmd/example/main_test.go | 11 ++ go.mod | 16 ++ go.sum | 46 ++++++ internal/example/main.go | 9 + main.go | 3 + pkg/example/main.go | 9 + renovate.json | 7 + tools/example/main.go | 9 + 28 files changed, 893 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .goreleaser.yml create mode 100644 CODEOWNERS create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 RELEASING.md create mode 100644 VERSIONING.md create mode 100644 ci/.gitignore create mode 100644 ci/README.md create mode 100644 ci/main.go create mode 100644 cmd/example/main.go create mode 100644 cmd/example/main_test.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/example/main.go create mode 100644 main.go create mode 100644 pkg/example/main.go create mode 100644 renovate.json create mode 100644 tools/example/main.go diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..4694510 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,57 @@ +name: Bug Report +description: File a bug report +title: "[Bug]: " +labels: + - "bug" +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: input + id: contact + attributes: + label: Contact Details + description: How can we get in touch with you if we need more info not publicly disclosable? + placeholder: ex. email@example.com + validations: + required: false + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Also tell us, what did you expect to happen? + placeholder: Tell us what you see! + value: "A bug happened!" + validations: + required: true + - type: input + id: version + attributes: + label: Version + description: What version of our software are you running? + validations: + required: true + - type: dropdown + id: platforms + attributes: + label: What platform are you seeing the problem on? + multiple: true + options: + - Not Applicable + - Qemu virt-ARM + - ASRock PAUL + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: Shell + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/u-bmc/u-bmc/blob/main/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..beeb6a5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: true +contact_links: + - name: Slack + url: https://slack.osfw.dev/ + about: Please ask and answer questions here. + - name: Discussions + url: https://github.com/orgs/u-bmc/discussions + about: For general discussion and design triage. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0495970 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +name: Build +on: + push: + branches: + - master + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + branches: + - master +permissions: + contents: read +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Run Build-Pipeline + uses: dagger/dagger-for-github@v5 + with: + verb: run + args: go run ci/main.go -cmd "go build -o output/ ./cmd/example/main.go" + version: "0.9.3" + - uses: actions/upload-artifact@v3 + with: + name: build-artifact + path: output diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bad9844 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Linting +on: + push: + branches: + - master + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + branches: + - master +permissions: + contents: read +jobs: + golangci-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..766d6b6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,86 @@ +name: Release +on: + push: + tags: + - "v*" +permissions: + contents: read +jobs: + release: + outputs: + hashes: ${{ steps.hash.outputs.hashes }} + permissions: + contents: write # needed for goreleaser to create a GitHub release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Fetch all tags + run: git fetch --force --tags + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Install Cosign + uses: sigstore/cosign-installer@v3 + - name: Install Syft + uses: anchore/sbom-action/download-syft@v0.15.0 + - name: Run GoReleaser + id: release-pipeline + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Generate subject + id: hash + env: + ARTIFACTS: "${{ steps.release-pipeline.outputs.artifacts }}" + run: | + set -euo pipefail + checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') + echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT" + provenance: + needs: [release] + permissions: + actions: read # to read the workflow path + id-token: write # to sign the provenance + contents: write # to add assets to a release + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 + with: + base64-subjects: "${{ needs.release.outputs.hashes }}" + upload-assets: true # upload to a new release + verification: + needs: [release, provenance] + runs-on: ubuntu-latest + permissions: read-all + steps: + - name: Install the verifier + uses: slsa-framework/slsa-verifier/actions/installer@v2.4.1 + - name: Download assets + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" + run: | + set -euo pipefail + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz" + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.zip" + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.sbom" + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$PROVENANCE" + - name: Verify assets + env: + CHECKSUMS: ${{ needs.release.outputs.hashes }} + PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" + run: | + set -euo pipefail + checksums=$(echo "$CHECKSUMS" | base64 -d) + while read -r line; do + fn=$(echo $line | cut -d ' ' -f2) + echo "Verifying $fn" + slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \ + --source-uri "github.com/$GITHUB_REPOSITORY" \ + --source-tag "$GITHUB_REF_NAME" \ + "$fn" + done <<< "$checksums" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d18d7e2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,72 @@ +name: Tests +on: + push: + branches: + - master + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + branches: + - master +permissions: + contents: read +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Run Test-Pipeline + uses: dagger/dagger-for-github@v5 + with: + verb: run + args: go run ci/main.go -cmd "go test -shuffle=on ./..." + version: "0.9.3" + race: + runs-on: ubuntu-latest + needs: + - test + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Run Race-Condition-Pipeline + uses: dagger/dagger-for-github@v5 + with: + verb: run + args: go run ci/main.go -cmd "go test -shuffle=on -race ./..." + version: "0.9.3" + coverage: + runs-on: ubuntu-latest + needs: + - test + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21" + check-latest: true + - name: Run Coverage-Pipeline + uses: dagger/dagger-for-github@v5 + with: + verb: run + args: go run ci/main.go -cmd "go test -shuffle=on -cover -covermode=atomic -coverpkg=./... -coverprofile=output/coverage.txt ./..." + version: "0.9.3" + - name: Upload report to Codecov + uses: codecov/codecov-action@v3 + with: + files: output/coverage.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53752db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +output diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..efcfad7 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,226 @@ +# See https://golangci-lint.run/usage/configuration/ +run: + issues-exit-code: 1 # Default + tests: true # Default + +linters: + # Disable everything by default so upgrades to not include new "default + # enabled" linters. + disable-all: true + # Specifically enable linters we want to use. + enable: + - asasalint + - bidichk + - bodyclose + - containedctx + - contextcheck + - cyclop + - dupword + - durationcheck + - errcheck + - errname + - errorlint + - exportloopref + - funlen + - gochecknoglobals + - gochecknoinits + - goconst + - godot + - gofumpt + - goheader + - gosec + - gosimple + - govet + - ineffassign + - misspell + - noctx + - nonamedreturns + - prealloc + - predeclared + - reassign + - revive + - staticcheck + - tenv + - testpackage + - typecheck + - unused + - whitespace + +issues: + # Maximum issues count per one linter. + # Set to 0 to disable. + # Default: 50 + # Setting to unlimited so the linter only is run once to debug all issues. + max-issues-per-linter: 0 + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + # Setting to unlimited so the linter only is run once to debug all issues. + max-same-issues: 0 + +linters-settings: + funlen: + # Checks the number of lines in a function. + # If lower than 0, disable the check. + # Default: 60 + lines: 100 + # Checks the number of statements in a function. + # If lower than 0, disable the check. + # Default: 40 + statements: -1 + godot: + exclude: + # Exclude links. + - '^ *\[[^]]+\]:' + # Exclude sentence fragments for lists. + - '^[ ]*[-•]' + # Exclude sentences prefixing a list. + - ':$' + goheader: + template: "SPDX-License-Identifier: BSD-3-Clause" + misspell: + locale: US + revive: + # Sets the default failure confidence. + # This means that linting errors with less than 0.8 confidence will be ignored. + # Default: 0.8 + confidence: 0.01 + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports + - name: blank-imports + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr + - name: bool-literal-in-expr + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr + - name: constant-logical-expr + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument + # TODO (#3372) reenable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280 + - name: context-as-argument + disabled: true + arguments: + - allowTypesBefore: "*testing.T" + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type + - name: context-keys-type + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit + - name: deep-exit + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer + - name: defer + disabled: false + arguments: + - ["call-chain", "loop"] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports + - name: dot-imports + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports + - name: duplicated-imports + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return + - name: early-return + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block + - name: empty-block + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines + - name: empty-lines + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming + - name: error-naming + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return + - name: error-return + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings + - name: error-strings + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf + - name: errorf + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported + - name: exported + disabled: false + arguments: + - "sayRepetitiveInsteadOfStutters" + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter + - name: flag-parameter + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches + - name: identical-branches + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return + - name: if-return + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement + - name: increment-decrement + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow + - name: indent-error-flow + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing + - name: import-shadowing + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments + - name: package-comments + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range + - name: range + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure + - name: range-val-in-closure + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address + - name: range-val-address + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id + - name: redefines-builtin-id + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format + - name: string-format + disabled: false + arguments: + - - panic + - '/^[^\n]*$/' + - must not contain line breaks + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag + - name: struct-tag + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else + - name: superfluous-else + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal + - name: time-equal + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming + - name: var-naming + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration + - name: var-declaration + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion + - name: unconditional-recursion + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return + - name: unexported-return + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error + - name: unhandled-error + disabled: false + arguments: + - "fmt.Fprint" + - "fmt.Fprintf" + - "fmt.Fprintln" + - "fmt.Print" + - "fmt.Printf" + - "fmt.Println" + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt + - name: unnecessary-stmt + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break + - name: useless-break + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value + - name: waitgroup-by-value + disabled: false diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..b276aa5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,80 @@ +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + - go mod tidy +gomod: + # Proxy a module from proxy.golang.org, making the builds verifiable. + # This will only be effective if running against a tag. Snapshots will ignore + # this setting. + # Notice: for this to work your `build.main` must be a package, not a `.go` file. + proxy: true + # If proxy is true, use these environment variables when running `go mod` + # commands (namely, `go mod tidy`). + # + # Default: `os.Environ()` merged with what you set the root `env` section. + env: + - GOPROXY=https://proxy.golang.org,direct + - GOSUMDB=sum.golang.org + # Sets the `-mod` flag value. + # + # Since: v1.7 + mod: mod +# Build for all first-class targets +builds: + - main: ./cmd/example + binary: example + env: ["CGO_ENABLED=0"] + goos: ["linux", "windows", "darwin"] + flags: ["-trimpath"] + ldflags: ["-s -w"] + targets: ["go_first_class"] + mod_timestamp: '{{ .CommitTimestamp }}' +# Non-Linux OS like Windows prefer a file extension +checksum: + name_template: 'checksums.txt' +# Split formats for different OS requirements +archives: + - format: tar.gz + # This name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # Use zip for Windows archives + format_overrides: + - goos: windows + format: zip +# Also bundle sources +source: + enabled: true +# Creates SBOMs of all archives and the source tarball using syft +# https://goreleaser.com/customization/sbom +sboms: + - artifacts: archive + - id: source # Two different sbom configurations need two different IDs + artifacts: source +# Name snapshot version 'next' +snapshot: + name_template: "{{ incpatch .Version }}-next" +# Generate changelog from conventional commits +changelog: + sort: asc + filters: + exclude: + - '^chore:' + - '^test:' + groups: + - title: 'New Features' + regexp: "^.*feat[(\\w)]*:+.*$" + order: 100 + - title: 'Bug fixes' + regexp: "^.*fix[(\\w)]*:+.*$" + order: 200 + - title: "Documentation updates" + regexp: "^.*docs[(\\w)]*:+.*$" + order: 400 + - title: 'Other work' + order: 999 diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..d59af54 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,8 @@ +# u-bmc CODEOWNERS +# +# Learn about CODEOWNERS file format: +# https://help.github.com/en/articles/about-code-owners +# + +* @u-bmc/maintainers +* @u-bmc/contributors diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3d51099 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +# See our [Code of Conduct](https://github.com/u-bmc/u-bmc/blob/main/CODE_OF_CONDUCT.md) in the projects main repository diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0af6dbc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +# See our [contributing guideline](https://github.com/u-bmc/u-bmc/blob/main/CONTRIBUTING.md) in the projects main repository diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d96d9d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, the u-bmc authors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f195cf8 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Template Repository + +## Files + +### `.golangci.yml` + +The configuration of the main linter in use. Visit the [golangci](https://golangci-lint.run/) website for more details. + +### `.goreleaser.yml` + +The configuration of the release tool in use. Visit the [goreleaser](https://goreleaser.com/) website for more details. + +### `renovate.json` + +The configuration of the dependency monitoring bot. Visit the [renovate](https://docs.renovatebot.com/) website for more details. + +## Directories + +### `/.github` + +Directory for GitHub specific configuration, but GitHub Actions and Issue Templates. + +### `/ci` + +This directory contains the sources for the CI helper tool which is based on Dagger. It allows easier reproduction of CI results locally. + +--- + +The following general directory structure recommendations are taken from the [project layout](https://github.com/golang-standards/project-layout) + +### `/cmd` + +Main applications for this project. + +The directory name for each application should match the name of the executable you want to have (e.g., `/cmd/myapp`). + +Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the `/pkg` directory. If the code is not reusable or if you don't want others to reuse it, put that code in the `/internal` directory. You'll be surprised what others will do, so be explicit about your intentions! + +It's common to have a small `main` function that imports and invokes the code from the `/internal` and `/pkg` directories and nothing else. + +### `/pkg` + +Library code that's ok to use by external applications (e.g., `/pkg/mypubliclib`). Other projects will import these libraries expecting them to work, so think twice before you put something here :-) Note that the `internal` directory is a better way to ensure your private packages are not importable because it's enforced by Go. The `/pkg` directory is still a good way to explicitly communicate that the code in that directory is safe for use by others. The [`I'll take pkg over internal`](https://travisjeffery.com/b/2019/11/i-ll-take-pkg-over-internal/) blog post by Travis Jeffery provides a good overview of the `pkg` and `internal` directories and when it might make sense to use them. + +### `/internal` + +Private application and library code. This is the code you don't want others importing in their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself. See the Go 1.4 [`release notes`](https://golang.org/doc/go1.4#internalpackages) for more details. Note that you are not limited to the top level `internal` directory. You can have more than one `internal` directory at any level of your project tree. + +### `/tools` + +Supporting tools for this project. Note that these tools can import code from the `/pkg` and `/internal` directories. diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..857609c --- /dev/null +++ b/RELEASING.md @@ -0,0 +1 @@ +# See our [release guideline](https://github.com/u-bmc/u-bmc/blob/main/RELEASING.md) in the projects main repository diff --git a/VERSIONING.md b/VERSIONING.md new file mode 100644 index 0000000..90b228e --- /dev/null +++ b/VERSIONING.md @@ -0,0 +1 @@ +# See our [versioning guideline](https://github.com/u-bmc/u-bmc/blob/main/VERSIONING.md) in the projects main repository diff --git a/ci/.gitignore b/ci/.gitignore new file mode 100644 index 0000000..550ecdd --- /dev/null +++ b/ci/.gitignore @@ -0,0 +1 @@ +ci diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000..f9c12a9 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,15 @@ +# Dagger CI Tool + +This tool wraps any command into a Go container to guarantee a clean environment. +Any artifacts stored at 'output/' will be exported from the container and the tool is meant to be invoked from the repository root. +Example usage standalone: + +```console +go run ci/main.go -cmd "go build -o output/" +``` + +Example usage with Dagger CLI: + +```console +dagger run go run ci/main.go -cmd "go build -o output/" +``` diff --git a/ci/main.go b/ci/main.go new file mode 100644 index 0000000..c111a65 --- /dev/null +++ b/ci/main.go @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import ( + "context" + "errors" + "flag" + "fmt" + "log" + "os" + "path/filepath" + "strings" + + "dagger.io/dagger" +) + +var ( + ErrTooFewArgs = errors.New("too few arguments") + ErrUnableToConnect = errors.New("unable to connect to client") + ErrGetPwd = errors.New("unable to get current work dir") + ErrMkdir = errors.New("unable to create directory") + ErrUnableToRun = errors.New("unable to run pipeline") +) + +func main() { + if err := run(); err != nil { + log.Fatalf("Error: %v", err) + } +} + +func run() error { + cmd := flag.String("cmd", "", "The command to be executed inside the golang container environment") + flag.Parse() + if len(*cmd) == 0 { + return ErrTooFewArgs + } + + ctx := context.Background() + client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) + if err != nil { + return fmt.Errorf("%w: %w", ErrUnableToConnect, err) + } + defer client.Close() + + pwd, err := os.Getwd() + if err != nil { + return fmt.Errorf("%w: %w", ErrGetPwd, err) + } + + src := client.Host().Directory(pwd) + + if err := os.MkdirAll(filepath.Join(pwd, "output"), os.ModePerm); err != nil { + return fmt.Errorf("%w: %w", ErrMkdir, err) + } + + if ok, err := client. + Container(). + From("golang:latest"). + WithMountedDirectory("/src", src). + WithWorkdir("/src"). + WithExec([]string{"mkdir", "-p", "/src/output"}). + WithExec(strings.Split(*cmd, " ")). + Directory("/src/output"). + Export(ctx, filepath.Join(pwd, "output")); !ok || err != nil { + return fmt.Errorf("%w: %w", ErrUnableToRun, err) + } + + return nil +} diff --git a/cmd/example/main.go b/cmd/example/main.go new file mode 100644 index 0000000..48a005c --- /dev/null +++ b/cmd/example/main.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import "log" + +func main() { + log.Println("Template") +} diff --git a/cmd/example/main_test.go b/cmd/example/main_test.go new file mode 100644 index 0000000..545bda6 --- /dev/null +++ b/cmd/example/main_test.go @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import ( + "testing" +) + +func TestFunc(t *testing.T) { + main() +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ce35e3b --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module github.com/u-bmc/go-project-template + +go 1.21 + +require dagger.io/dagger v0.9.3 + +require ( + github.com/99designs/gqlgen v0.17.31 // indirect + github.com/Khan/genqlient v0.6.0 // indirect + github.com/adrg/xdg v0.4.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/vektah/gqlparser/v2 v2.5.6 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect + golang.org/x/sync v0.4.0 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..791f56c --- /dev/null +++ b/go.sum @@ -0,0 +1,46 @@ +dagger.io/dagger v0.9.3 h1:igFU1d6R933Jn6741k5HI/TjAlkpb2/wiBTypNbE0Pw= +dagger.io/dagger v0.9.3/go.mod h1:1iiFzqKOri9kJxUDYUibthMpkfzaWP25B2kx7F/AXIk= +github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158= +github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4= +github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk= +github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM= +github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= +github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= +github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU= +github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/example/main.go b/internal/example/main.go new file mode 100644 index 0000000..48a005c --- /dev/null +++ b/internal/example/main.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import "log" + +func main() { + log.Println("Template") +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..de86783 --- /dev/null +++ b/main.go @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package template diff --git a/pkg/example/main.go b/pkg/example/main.go new file mode 100644 index 0000000..48a005c --- /dev/null +++ b/pkg/example/main.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import "log" + +func main() { + log.Println("Template") +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..9a0fc49 --- /dev/null +++ b/renovate.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base", ":semanticCommits"], + "prBodyTemplate": "{{{table}}}{{{notes}}}{{{changelogs}}}", + "prConcurrentLimit": 5, + "schedule": ["every weekend"] +} diff --git a/tools/example/main.go b/tools/example/main.go new file mode 100644 index 0000000..48a005c --- /dev/null +++ b/tools/example/main.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import "log" + +func main() { + log.Println("Template") +}