From 474de0691cacc8bf2df41eded30a9e77773df6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Corrales=20Solera?= Date: Mon, 17 Apr 2023 13:54:24 +0200 Subject: [PATCH] Initial commit --- .githooks/pre-commit | 3 + .github/ISSUE_TEMPLATE/bug_report.yml | 71 +++++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/ISSUE_TEMPLATE/feature_request.yaml | 60 ++++++ .github/dependabot.yml | 18 ++ .github/release-drafter.yml | 56 ++++++ .github/workflows/build.yml | 18 ++ .github/workflows/codeql.yml | 31 +++ .github/workflows/linter.yml | 23 +++ .github/workflows/release-drafter.yml | 17 ++ .gitignore | 37 ++++ .go-version | 1 + .golangci.yml | 103 ++++++++++ CODEOWNERS | 1 + CODE_OF_CONDUCT.md | 74 +++++++ CONTRIBUTING.md | 31 +++ LICENSE | 201 ++++++++++++++++++++ Makefile | 23 +++ README.md | 60 ++++++ build/code.mk | 20 ++ build/deps.mk | 6 + build/test.mk | 28 +++ build/tools.mk | 8 + go.mod | 159 ++++++++++++++++ tools/go.mod | 10 + tools/tools.go | 10 + 26 files changed, 1074 insertions(+) create mode 100755 .githooks/pre-commit create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yaml create mode 100644 .github/dependabot.yml create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/linter.yml create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .gitignore create mode 100644 .go-version create mode 100644 .golangci.yml create mode 100644 CODEOWNERS create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 build/code.mk create mode 100644 build/deps.mk create mode 100644 build/test.mk create mode 100644 build/tools.mk create mode 100644 go.mod create mode 100644 tools/go.mod create mode 100644 tools/tools.go diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..ded474b --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,3 @@ +#!/bin/bash + +make fmt \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..ec7c40b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,71 @@ +name: "🐛 Bug Report" +description: Create a new ticket for a bug. +title: "🐛 [BUG] - " +labels: ["bug"] +body: + - type: input + id: version + attributes: + label: "Version" + description: Please enter the version of this module that produced the issue + placeholder: vX.Y.Z or the commit hash of the version. + validations: + required: true + - type: dropdown + id: os + attributes: + label: "OS" + description: What is your environment ? + multiple: true + options: + - Windows + - Linux + - Mac + validations: + required: false + - type: textarea + id: description + attributes: + label: "Description" + description: Please enter an explicit description of your issue + placeholder: Short and explicit description of your incident... + validations: + required: true + - type: textarea + id: reprod + attributes: + label: "Reproduction steps" + description: Please enter an explicit description of your issue + value: | + 1. '...' + 2. '....' + 3. '....' + 4. See error + render: bash + validations: + required: true + - type: textarea + id: screenshot + attributes: + label: "Screenshots" + description: If applicable, add screenshots to help explain your problem. + value: | + ![DESCRIPTION](LINK.png) + render: bash + validations: + required: false + - type: checkboxes + id: no-duplicate-issues + attributes: + label: "👀 Have you spent some time to check if this issue has been raised before?" + description: "Have you researched on internet for a similar issue or checked our older issues for a similar bug?" + options: + - label: "I checked and didn't find similar issue" + required: true + - type: checkboxes + id: read-code-of-conduct + attributes: + label: "🏢 Have you read the Code of Conduct?" + options: + - label: "I have read the [Code of Conduct](https://github.com/{{.repository.owner}}/{{.repository.name}}/blob/main/CODE_OF_CONDUCT.md)" + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0e590e3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Support Questions + url: https://github.com/{{.repository.owner}}/{{.repository.name}}/discussions/new + about: Need support & not sure if this a bug? You can ask questions in Slack or GitHub discussions. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml new file mode 100644 index 0000000..9e13b2c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -0,0 +1,60 @@ +name: "💡 Feature Request" +description: Create a new ticket for a new feature request +title: "💡 [REQUEST] - <title>" +labels: ["question"] +body: + - type: input + id: start_date + attributes: + label: "Start Date" + description: Start of development + placeholder: "month/day/year" + validations: + required: false + - type: textarea + id: implementation_pr + attributes: + label: "Implementation PR" + description: Pull request used + placeholder: "#Pull Request ID" + validations: + required: false + - type: textarea + id: reference_issues + attributes: + label: "Reference Issues" + description: Common issues + placeholder: "#Issues IDs" + validations: + required: false + - type: textarea + id: summary + attributes: + label: "Summary" + description: Provide a brief explanation of the feature + placeholder: Describe in a few lines your feature request + validations: + required: true + - type: textarea + id: drawbacks + attributes: + label: "Drawbacks" + description: What are the drawbacks/impacts of your feature request ? + placeholder: Identify the drawbacks and impacts while being neutral on your feature request + validations: + required: true + - type: textarea + id: unresolved_question + attributes: + label: "Unresolved questions" + description: What questions still remain unresolved ? + placeholder: Identify any unresolved issues. + validations: + required: false + - type: checkboxes + id: read-code-of-conduct + attributes: + label: "🏢 Have you read the Code of Conduct?" + options: + - label: "I have read the [Code of Conduct](https://github.com/{{.repository.owner}}/{{.repository.name}}/blob/main/CODE_OF_CONDUCT.md)" + required: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e31ea8a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +version: 2 +updates: + # Maintain dependencies for gh actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every week + interval: "daily" + # Maintain dependencies for go + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + # Maintain dependencies for docker + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..cb72d0f --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,56 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +template: | + ## What Changed 👀 + + $CHANGES + + ## Contributors + $CONTRIBUTORS +categories: + - title: 🚀 Features + labels: + - feature + - enhancement + - title: 🐛 Bug Fixes + labels: + - fix + - bug + - title: ⚠️ Changes + labels: + - changed + - title: ⛔️ Deprecated + labels: + - deprecated + - title: 🗑 Removed + labels: + - removed + - title: 🔐 Security + labels: + - security + - title: 📄 Documentation + labels: + - docs + - documentation + - title: 🧩 Dependency Updates + labels: + - deps + - dependencies + collapse-after: 5 + +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - major + minor: + labels: + - minor + patch: + labels: + - patch + default: patch + +exclude-labels: + - skip-changelog \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8c9027f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ["1.20"] + steps: + - uses: actions/checkout@v3 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Test + run: make test diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..f7eccb8 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,31 @@ +name: "CodeQL" + +on: + pull_request: + branches: [ "main" ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..1e6fc4e --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,23 @@ +name: Static Analysis +on: + pull_request: + branches: + - main +permissions: + contents: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ "1.20" ] + steps: + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..cdcbc4a --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,17 @@ +name: Release Drafter +on: + push: + branches: [ "main" ] +permissions: + id-token: write + contents: write + issues: write + pull-requests: write +jobs: + releaseDrafter: + runs-on: ubuntu-latest + steps: + - name: Run release-drafter + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..304813f --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# OSX leaves these everywhere on SMB shares +._* + +# OSX trash +.DS_Store + +# Developers can store local stuff in dirs named __something +__* + +# Eclipse files +.classpath +.project +.settings/** + +# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA +.idea/ +*.iml + +# Coverage test output from gotest +coverage.* + +## binary files +dist + +## Go vendors +vendor + +## Reports +golangci-* + +## Temporary resources for testing purpose +tmp +**/tmp/** + +## Temporary markdown files +TODO.md + diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..5fb5a6b --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.20 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f9825e5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,103 @@ +#This file contains all available configuration options +# with their default values. + +# options for analysis running +run: + concurrency: 1 + deadline: 5m + issues-exit-code: 1 + tests: false + build-tags: + - latest + skip-dirs: + - doc + - vendor + - testdata + - internal/testfuncs + - tools + - build + - log + skip-files: + - golangci.yml + - lib/bad.go + +output: + format: colored-line-number,checkstyle:golangci-report.xml + print-issued-lines: true + print-linter-name: true + +linters-settings: + errcheck: + check-type-assertions: true + check-blank: false + funlen: + statements: 70 + lines: 70 + govet: + check-shadowing: true + golint: + min-confidence: 1 + gofmt: + simplify: true + goimports: + local-prefixes: github.com/astrokube/scaffolder + gocyclo: + min-complexity: 25 + gocognit: + min-complexity: 55 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + depguard: + include-go-root: false + packages: + - github.com/davecgh/go-spew/spew + misspell: + locale: US + lll: + line-length: 120 + tab-width: 1 + unused: + check-exported: false + unparam: + algo: cha + check-exported: false + nakedret: + max-func-lines: 50 + prealloc: + simple: true + range-loops: true # Report preallocation suggestions on range loops, true by default + for-loops: false # Report preallocation suggestions on for loops, false by default + wrapcheck: + ignorePackageGlobs: + - github.com/{{.repository.owner}}/{{.repository.name}}/* +issues: + exclude: + - "not declared by package utf8" + - "unicode/utf8/utf8.go" + +linters: + enable-all: true + disable: + - deadcode + - maligned + - varcheck + - ifshort + - golint + - interfacer + - exhaustivestruct + - nosnakecase + - scopelint + - structcheck + - godox + - ireturn + - goerr113 + - gochecknoglobals + - gochecknoinits + - wsl + - nlreturn + fast: true diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..b0624a5 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @{{.repository.owner}}/devs \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..888998e --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [engineering@astrokube.com](engineering@astrokube.com]). All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e771846 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ + +# Contributing guidelines + +This document describes how to contribute to the development of this plugin. + +First of all, thanks for wishing to contribute to [Astrokube](https://www.astrokube.com/) and helping us to provide with this Go SDK opensource community We appreciate the help! + +This repository is one of many across the Astronetes ecosystem, and we welcome contributions to them all. In the same way, we encourage you to discuss the change you wish to make via issue, email, or any other method with the owners of this repository before working on a new feature. + +Please note we have a code of conduct, please follow it in all your interactions with the project. + +## Code of conduct + +Please make sure to read and observe our [Contributor Code of Conduct](CODE_OF_CONDUCT,md). + +## Prerequisites + +* [go](https://go.dev/doc/install version v1.20+ + +## Contributing steps + +1. Submit an issue describing your proposed change to the repo in question. +2. The [code owners](CODEOWNERS) will respond to your issue promptly. +3. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). +4. Fork the desired repo, develop and test your code changes. +5. Submit a pull request. + +## How to build the sdk-go module locally + +Once you have completed the changes and added new tests you just need to run teh command `make` to check that everything +works as expected. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d33284 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02d8d16 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +PROJECT_NAME := github.com/{{.repository.owner}}/{{.repository.name}}" +GO_VERSION := $(shell cat .go-version) +GO = GOFLAGS=-mod=readonly go +GO_CMD ?= go +UNAME := $(shell uname) + +all: init fmt test lint + +help: ## Display this help screen + @echo "Makefile targets:" + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " * \033[36m%-15s\033[0m %s\n", $$1, $$2}' + +.PHONY: init +init: git-hooks tools deps ## setup hooks & install tools and deps + +.PHONY: clean +clean: test-clean ## remove the temporary resources + @echo "=== $(PROJECT_NAME) === [ clean ]: removing binaries and coverage file..." + +include build/tools.mk +include build/deps.mk +include build/code.mk +include build/test.mk diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfa4ebb --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +[![GitHub Release](https://img.shields.io/github/v/release/{{.repository.owner}}/{{.repository.name}})](https://github.com/{{.repository.owner}}/{{.repository.name}}/releases) +[![Go Reference](https://pkg.go.dev/badge/github.com/{{.repository.owner}}/{{.repository.name}}.svg)](https://pkg.go.dev/github.com/{{.repository.owner}}/{{.repository.name}}) +[![go.mod](https://img.shields.io/github/go-mod/go-version/{{.repository.owner}}/{{.repository.name}})](go.mod) +[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://img.shields.io/github/license/{{.repository.owner}}/{{.repository.name}}) +[![Build Status](https://img.shields.io/github/actions/workflow/status/{{.repository.owner}}/{{.repository.name}}/build.yml?branch=main)](https://github.com/{{.repository.owner}}/{{.repository.name}}/actions?query=workflow%3ABuild+branch%3Amain) +[![CodeQL](https://github.com/{{.repository.owner}}/{{.repository.name}}/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/{{.repository.owner}}/{{.repository.name}}/actions/workflows/codeql.yml) + +# {{.project}} + +{{.description}} + +## History and project status + +This module is still `in active development` and the API is still subject to breaking changes. + +## Installation + +Use go get to retrieve the library to add it to your GOPATH workspace, or project's Go module dependencies. + +```bash +go get -u github.com/{{.repository.owner}}/{{.repository.name}} +``` + +To update the library use go get -u to retrieve the latest version of it. + +```bash +go get -u github.com/{{.repository.owner}}/{{.repository.name}} +``` + +You could specify a concrete version of this module as It's shown on the below. Replace x.y.z by the desired version. + +```bash +module github.com/<org>/<repository> +require ( + github.com/{{.repository.owner}}/{{.repository.name}} vX.Y.Z +) +``` + +## Overview of packages + +The library is composed by: + +* `package`: ..... + +## Getting started + +### Pre-requisites + +* Go 1.19+ + +### Examples + +A rich and growing set of examples of usage of this module can be found in folder `examples`. + + +### Contributing + +See the [contributing](https://github.com/{{.repository.owner}}/{{.repository.name}}/blob/main/CONTRIBUTING.md) documentation. + + diff --git a/build/code.mk b/build/code.mk new file mode 100644 index 0000000..9d368cf --- /dev/null +++ b/build/code.mk @@ -0,0 +1,20 @@ +GOIMPORT = goimport +GOFUMPT = gofumpt +GOLINTER ?= golangci-lint +GIT_HOOKS_PATH ?= .githooks + +.PHONY: git-hooks +git-hooks: ## setup githooks for the local repository + @echo "=== $(PROJECT_NAME) === [ git-hooks ]: Configuring git hooks..." + git config core.hooksPath $(GIT_HOOKS_PATH) + +.PHONY: fmt +fmt: ## format the code + @echo "=== $(PROJECT_NAME) === [ fmt ]: formatting the code with goimport..." + @#$($(GOFUMPT) $(find . -type f -name '*.go' -not -path "./vendor/*") + @goimports -w . && gofumpt -w . + +.PHONY: lint +lint: + @echo "=== $(PROJECT_NAME) === [ lint ]: Validating source code running $(GOLINTER)..." + $(GOLINTER) run ./... \ No newline at end of file diff --git a/build/deps.mk b/build/deps.mk new file mode 100644 index 0000000..e7039a7 --- /dev/null +++ b/build/deps.mk @@ -0,0 +1,6 @@ +VENDOR_CMD = $(GO_CMD) mod vendor + +.PHONY: deps +deps: ## install dependencies + @echo "=== $(PROJECT_NAME) === [ deps ]: Installing package dependencies required by the project..." + @$(VENDOR_CMD) \ No newline at end of file diff --git a/build/test.mk b/build/test.mk new file mode 100644 index 0000000..f69dbd7 --- /dev/null +++ b/build/test.mk @@ -0,0 +1,28 @@ +COVERAGE_FILE ?= coverage.out +COVERAGE_REPORT ?= coverage.html +COVERAGE_XML ?= coverage.xml +TEST_TIMEOUT = 300 + +.PHONY: test-init +test-init: ## download temporary resources for tests + sh $(PWD)/scripts/setup-testdata.sh + +.PHONY: test +test: ## run unit tests + @echo "=== $(PROJECT_NAME) === [ test ]: running unit tests..." + @$(GO) test -timeout $(TEST_TIMEOUT)s -race -v ./... + +.PHONY: test-coverage +test-coverage: ## run unit tests with coverage + @echo "=== $(PROJECT_NAME) === [ test-coverage ]: running unit tests with coverage..." + @$(GO) test -timeout $(TEST_TIMEOUT)s -race -v -covermode=atomic -coverpkg=./... -coverprofile $(COVERAGE_FILE) ./... + @$(GO) tool cover -func $(COVERAGE_FILE) + @$(GO) tool cover -html $(COVERAGE_FILE) -o $(COVERAGE_REPORT) + @gocov convert $(COVERAGE_FILE) | gocov-xml > $(COVERAGE_XML) + + +.PHONY: test-clean +test-clean: ## remove coverage files + @rm -f $(COVERAGE_FILE) $(COVERAGE_REPORT) + + diff --git a/build/tools.mk b/build/tools.mk new file mode 100644 index 0000000..bb5ef50 --- /dev/null +++ b/build/tools.mk @@ -0,0 +1,8 @@ +TOOL_DIR ?= tools + +.PHONY: tools +tools: ## install required tools + @echo "=== $(PROJECT_NAME) === [ tools ]: Installing tools required by the project..." + @cd $(TOOL_DIR) && $(GO) mod download + @cd $(TOOL_DIR) && cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install % + @cd $(TOOL_DIR) && $(GO) mod tidy \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..86950f7 --- /dev/null +++ b/go.mod @@ -0,0 +1,159 @@ +module github.com/{{.repository.owner}}/{{.repository.name}} + +go 1.20 + +require ( + github.com/ghodss/yaml v1.0.0 + github.com/go-logr/logr v1.2.3 + github.com/google/go-cmp v0.5.9 + github.com/hairyhenderson/go-fsimpl v0.0.0-20230408234157-f9bd3abe0dd7 + go.opentelemetry.io/otel/trace v1.14.0 + golang.org/x/exp v0.0.0-20230321023759-10a507213a29 + helm.sh/helm/v3 v3.11.3 + k8s.io/cli-runtime v0.26.0 + k8s.io/kubectl v0.26.0 + sigs.k8s.io/controller-runtime v0.14.6 +) + +require ( + github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect + github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/BurntSushi/toml v1.2.1 // indirect + github.com/MakeNowJust/heredoc v1.0.0 // indirect + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/sprig/v3 v3.2.3 // indirect + github.com/Masterminds/squirrel v1.5.3 // indirect + github.com/Microsoft/go-winio v0.6.0 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec // indirect + github.com/acomagu/bufpipe v1.0.4 // indirect + github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/chai2010/gettext-go v1.0.2 // indirect + github.com/cloudflare/circl v1.3.2 // indirect + github.com/containerd/containerd v1.7.0 // indirect + github.com/cyphar/filepath-securejoin v0.2.3 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/cli v20.10.21+incompatible // indirect + github.com/docker/distribution v2.8.1+incompatible // indirect + github.com/docker/docker v20.10.24+incompatible // indirect + github.com/docker/docker-credential-helpers v0.7.0 // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-metrics v0.0.1 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/emicklei/go-restful/v3 v3.10.1 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/evanphx/json-patch v5.6.0+incompatible // indirect + github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/go-errors/errors v1.0.1 // indirect + github.com/go-git/gcfg v1.5.0 // indirect + github.com/go-git/go-billy/v5 v5.4.1 // indirect + github.com/go-git/go-git/v5 v5.6.1 // indirect + github.com/go-gorp/gorp/v3 v3.0.5 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.20.0 // indirect + github.com/go-openapi/swag v0.19.14 // indirect + github.com/gobwas/glob v0.2.3 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/btree v1.0.1 // indirect + github.com/google/gnostic v0.5.7-v3refs // indirect + github.com/google/gofuzz v1.2.0 // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/gorilla/mux v1.8.0 // indirect + github.com/gosuri/uitable v0.0.4 // indirect + github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/huandu/xstrings v1.4.0 // indirect + github.com/imdario/mergo v0.3.15 // indirect + github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jmoiron/sqlx v1.3.5 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/klauspost/compress v1.16.0 // indirect + github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect + github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect + github.com/lib/pq v1.10.7 // indirect + github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect + github.com/mailru/easyjson v0.7.6 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-wordwrap v1.0.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/moby/locker v1.0.1 // indirect + github.com/moby/spdystream v0.2.0 // indirect + github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect + github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/client_golang v1.14.0 // indirect + github.com/prometheus/client_model v0.3.0 // indirect + github.com/prometheus/common v0.37.0 // indirect + github.com/prometheus/procfs v0.8.0 // indirect + github.com/rubenv/sql-migrate v1.3.1 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sergi/go-diff v1.3.1 // indirect + github.com/shopspring/decimal v1.3.1 // indirect + github.com/sirupsen/logrus v1.9.0 // indirect + github.com/skeema/knownhosts v1.1.0 // indirect + github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/cobra v1.6.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/xeipuuv/gojsonschema v1.2.0 // indirect + github.com/xlab/treeprint v1.1.0 // indirect + go.opentelemetry.io/otel v1.14.0 // indirect + go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect + golang.org/x/crypto v0.8.0 // indirect + golang.org/x/mod v0.9.0 // indirect + golang.org/x/net v0.9.0 // indirect + golang.org/x/oauth2 v0.6.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.7.0 // indirect + golang.org/x/term v0.7.0 // indirect + golang.org/x/text v0.9.0 // indirect + golang.org/x/time v0.3.0 // indirect + golang.org/x/tools v0.7.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20230331144136-dcfb400f0633 // indirect + google.golang.org/grpc v1.54.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/api v0.26.2 // indirect + k8s.io/apiextensions-apiserver v0.26.1 // indirect + k8s.io/apimachinery v0.26.2 // indirect + k8s.io/apiserver v0.26.2 // indirect + k8s.io/client-go v0.26.2 // indirect + k8s.io/component-base v0.26.2 // indirect + k8s.io/klog/v2 v2.90.1 // indirect + k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect + k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect + oras.land/oras-go v1.2.2 // indirect + sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect + sigs.k8s.io/kustomize/api v0.12.1 // indirect + sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect +) diff --git a/tools/go.mod b/tools/go.mod new file mode 100644 index 0000000..dd5ebe8 --- /dev/null +++ b/tools/go.mod @@ -0,0 +1,10 @@ +module github.com/{{.repository.owner}}/{{.repository.name}}/build + +go 1.20 + +require ( + github.com/golangci/golangci-lint v1.52.2 + golang.org/x/tools v0.7.0 + mvdan.cc/gofumpt v0.4.0 +) + diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..68dc218 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,10 @@ +//go:build tools +// +build tools + +package tools + +import ( + _ "github.com/golangci/golangci-lint/cmd/golangci-lint" + _ "golang.org/x/tools/cmd/goimports" + _ "mvdan.cc/gofumpt" +)