From f9f4be525e56b70c9a1b9ddf27aa03f1d0970eaf Mon Sep 17 00:00:00 2001 From: Scott D DeWitt <54076100+sdewitt-newrelic@users.noreply.github.com> Date: Wed, 10 May 2023 10:46:46 -0400 Subject: [PATCH] Merge all workflow updates (#6) * feat(actions): added release action * feat(actions): add write all permission * feat(build): add lambda Dockerfile * feat(build): add goreleaser for lambda * feat(build): skip changelog for docker build * feat(actions): do not run build/repolinter on all push * feat(git): add git pre-commit hook * feat(build): Updated to work with pre-commit * feat(build): add pre-commit * feat(build): add gobin to path * feat(build): added commitlint * feat(build): run commitlint in validate action * feat(build): set fetch-depth to 2 * ci: add pull request template --- .editorconfig | 2 -- .github/ISSUE_TEMPLATE/enhancement.md | 27 --------------- .github/ISSUE_TEMPLATE/feature_request.md | 17 ++++++++++ .github/pull_request_template.md | 28 ++++++++++++++++ .github/workflows/build.yml | 11 +++---- .github/workflows/release.yml | 40 +++++++++++++++++++++++ .github/workflows/repolinter.yml | 7 ++-- .github/workflows/validate.yml | 40 +++++++++++++++++++++++ .gitignore | 2 +- .goreleaser-lambda.yaml | 37 +++++++++++++++++++++ .goreleaser.yaml | 33 +++---------------- .pre-commit-config.yaml | 31 ++++++++++++++++++ commitlint.config.js | 1 + configs/config.sample.yml | 1 - scripts/README.md | 2 +- test/README.md | 2 -- 16 files changed, 209 insertions(+), 72 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/enhancement.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/validate.yml create mode 100644 .goreleaser-lambda.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 commitlint.config.js diff --git a/.editorconfig b/.editorconfig index 40d26e4..c24c49d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,5 +12,3 @@ max_line_length = 80 [*.md] max_line_length = 0 trim_trailing_whitespace = false - - diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md deleted file mode 100644 index 0907a9f..0000000 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Enhancement request -about: Suggest an idea for a future version of this project -title: '' -labels: enhancement, needs-triage -assignees: '' - ---- - -[NOTE]: # ( ^^ Provide a general summary of the request in the title above. ^^ ) - -## Summary - -[NOTE]: # ( Provide a brief overview of what the new feature is all about. ) - -## Desired Behavior - -[NOTE]: # ( Tell us how the new feature should work. Be specific. ) -[TIP]: # ( Do NOT give us access or passwords to your New Relic account or API keys! ) - -## Possible Solution - -[NOTE]: # ( Not required. Suggest how to implement the addition or change. ) - -## Additional context - -[TIP]: # ( Why does this feature matter to you? What unique circumstances do you have? ) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..5744bb4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +### Feature Description +A clear and concise description of the feature you want or need. + +### Describe Alternatives +A clear and concise description of any alternative solutions or features you've considered. Are there examples you could link us to? + +### Additional context +Add any other context here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..371537e --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,28 @@ +# Description + +Please include a summary of the changes and the related issue. + +## Type of change + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing + functionality to not work as expected) +- [ ] This change requires a documentation update + +# How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. + +- [ ] Test A +- [ ] Test B + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b551543..8738f9f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,20 +1,17 @@ # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go -name: Go +name: Build & Test -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] +on: [pull_request] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout repo + uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7c971dd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +# This workflow will release a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Release + +permissions: write-all + +on: + push: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + + - name: Generate new tag + uses: obfu5c8/action-svu@v1 + id: generate_next_version + with: + force-increment: true + + - name: Tag latest commit + run: | + git tag ${{ steps.generate_next_version.outputs.version }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/repolinter.yml b/.github/workflows/repolinter.yml index d3db361..4c4e85c 100644 --- a/.github/workflows/repolinter.yml +++ b/.github/workflows/repolinter.yml @@ -1,14 +1,15 @@ # NOTE: This file should always be named `repolinter.yml` to allow # workflow_dispatch to work properly -name: Repolinter Action +name: Repolinter # NOTE: This workflow will ONLY check the default branch! # Currently there is no elegant way to specify the default # branch in the event filtering, so branches are instead # filtered in the "Test Default Branch" step. -on: [push, workflow_dispatch] +on: [pull_request, workflow_dispatch] jobs: + repolint: name: Run Repolinter runs-on: ubuntu-latest @@ -20,9 +21,11 @@ jobs: script: | const data = await github.repos.get(context.repo) return data.data && data.data.default_branch === context.ref.split('/').slice(-1)[0] + - name: Checkout Self if: ${{ steps.default-branch.outputs.result == 'true' }} uses: actions/checkout@v2 + - name: Run Repolinter if: ${{ steps.default-branch.outputs.result == 'true' }} uses: newrelic/repolinter-action@v1 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..97112aa --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,40 @@ +# This workflow will validate a golang project + +name: Validate + +on: [push] + +jobs: + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Set up Go + uses: actions/setup-go@v3 + + - name: Set up Python + uses: actions/setup-python@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + + - name: Add GOBIN to PATH + run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + shell: bash + + - name: Install staticcheck + run: "go install 'honnef.co/go/tools/cmd/staticcheck@latest'" + + - name: Run pre-commit + uses: pre-commit/action@v3.0.0 + + - name: Install commitlint + run: "npm install -g @commitlint/cli @commitlint/config-conventional" + + - name: Lint last commit message + run: "commitlint --from HEAD~1 --to HEAD --verbose" diff --git a/.gitignore b/.gitignore index 7c218a7..978f883 100644 --- a/.gitignore +++ b/.gitignore @@ -123,4 +123,4 @@ config.yml dist/ cf-params.json -.build.env +__tools/ diff --git a/.goreleaser-lambda.yaml b/.goreleaser-lambda.yaml new file mode 100644 index 0000000..d49f403 --- /dev/null +++ b/.goreleaser-lambda.yaml @@ -0,0 +1,37 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +builds: + - id: lambda + main: ./cmd/nr-entity-tag-sync-lambda/nr-entity-tag-sync-lambda.go + binary: nr-entity-tag-sync-lambda + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + +archives: + - format: binary + +dockers: + - id: lambda-image + ids: + - lambda + image_templates: + - "{{ .Env.AWS_ECR_REPO_URI }}:latest" + - "{{ .Env.AWS_ECR_REPO_URI }}:{{ .Tag }}" + dockerfile: ./deployments/Dockerfile-lambda + extra_files: + - configs/config.yml + +changelog: + skip: true + +release: + disable: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 218e2a7..3cae876 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,35 +12,14 @@ builds: - CGO_ENABLED=0 goos: - linux - #- windows - #- darwin + - windows + - darwin goarch: + - "386" - amd64 - - id: lambda - main: ./cmd/nr-entity-tag-sync-lambda/nr-entity-tag-sync-lambda.go - binary: nr-entity-tag-sync-lambda - env: - - CGO_ENABLED=0 - goos: - - linux - goarch: - - amd64 - -dockers: - - id: lambda-image - ids: - - lambda - image_templates: - - "{{ .Env.AWS_ECR_REPO_URI }}:latest" - - "{{ .Env.AWS_ECR_REPO_URI }}:{{ .Tag }}" - dockerfile: ./deployments/Dockerfile-lambda - extra_files: - - configs/config.yml archives: - format: tar.gz - builds: - - standalone # this name template makes the OS and Arch compatible with the results of uname. name_template: >- {{ .ProjectName }}_ @@ -59,14 +38,10 @@ checksum: snapshot: name_template: "{{ incpatch .Version }}-next" + changelog: sort: asc filters: exclude: - '^docs:' - '^test:' - -# The lines beneath this are called `modelines`. See `:help modeline` -# Feel free to remove those if you don't want/use them. -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5ef3f19 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +default_stages: +- commit +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-json + - id: check-shebang-scripts-are-executable + - id: check-yaml + exclude: cf-template.yaml + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace +- repo: https://github.com/Bahjat/pre-commit-golang + rev: v1.0.3 + hooks: + - id: go-vet + - id: go-unit-tests + - id: go-static-check # install https://staticcheck.io/docs/ +- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v9.5.0 + hooks: + - id: commitlint + stages: + - commit-msg + additional_dependencies: ['@commitlint/config-conventional'] diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..4fedde6 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = { extends: ['@commitlint/config-conventional'] } diff --git a/configs/config.sample.yml b/configs/config.sample.yml index d129eae..c14ea5b 100644 --- a/configs/config.sample.yml +++ b/configs/config.sample.yml @@ -24,4 +24,3 @@ mappings: sys_id: SNOW_CMDB_CI environment: SNOW_ENVIRONMENT sys_domain.value: SNOW_SYS_DOMAIN - diff --git a/scripts/README.md b/scripts/README.md index edb724e..2f8a654 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -8,4 +8,4 @@ Examples: * https://github.com/kubernetes/helm/tree/master/scripts * https://github.com/cockroachdb/cockroach/tree/master/scripts -* https://github.com/hashicorp/terraform/tree/master/scripts \ No newline at end of file +* https://github.com/hashicorp/terraform/tree/master/scripts diff --git a/test/README.md b/test/README.md index cdcf65f..72e4a5e 100644 --- a/test/README.md +++ b/test/README.md @@ -5,5 +5,3 @@ Additional external test apps and test data. Feel free to structure the `/test` Examples: * https://github.com/openshift/origin/tree/master/test (test data is in the `/testdata` subdirectory) - -