Skip to content

Commit

Permalink
fix: updated dependencies, improved coverage, and minor fixes
Browse files Browse the repository at this point in the history
* test: added code coverage

* test: fixed race condition bug

* test: version tests

* test: gocilint-fix

* test: added more test

* test: region validation flags

* test: more tests

* test: added test containers

* test: added test containers2

* test: added test containers3

* test: added test containers5

* test: region validation flags

* test: cleanup provider

* test: clearing

* test: clearing

* ci: removed upload step

* test: added more tests

* test: added test for alias and versions func

* test: executeClean test

* test: executeClean test

* test: executeClean test

* test: executeClean test

* test: executeClean test

* test: executeClean test

* test: versionCMD test

* fix: removed global variable issues

* fix: removed global variable issues

* ci: added logic to prevent duplicate tests for PRs

* ci: added codecov yml

* ci: added codecov yml-2

* test: added test for root invocation

* test: added test for root invocation

* chore: ready for merge

* test: added invalid custom file tests

* test: added more test cases

* test: fixed broken test

* test: added invalid custom file tests
  • Loading branch information
karl-cardenas-coding authored Nov 27, 2023
1 parent 7f1ecb6 commit 8e67800
Show file tree
Hide file tree
Showing 34 changed files with 2,942 additions and 476 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release to Production
name: Release

on:
push:
Expand Down
43 changes: 32 additions & 11 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
name: PR-Review
name: Pull Request Checks

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [ main ]
env:
GITHUB_TOKEN: ${{ github.token }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
LINT_VERSION: "1.25.1"

permissions:
contents: read
packages: write

jobs:

run-ci:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
if: ${{ !github.event.pull_request.draft }}
steps:
# If the condition above is not met, aka, the PR is not in draft status, then this step is skipped.
# Because this step is part of the critical path, omission of this step will result in remaining CI steps not gettinge executed.
# As of 8/8/2022 there is now way to enforce this beahvior in GitHub Actions CI.
- run: exit 0

test:
needs: [run-ci]
outputs:
VERSION: ${{ steps.go.outputs.version }}
name: Test
Expand All @@ -33,6 +46,9 @@ jobs:


- name: Generate AWS region file
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws ec2 describe-regions --all-regions --region us-east-1 --query "Regions[].RegionName" --output text >> cmd/aws-regions.txt
Expand All @@ -42,15 +58,25 @@ jobs:
args: -v

- name: Execute Go tests
run: go get && go test -v ./...
run: make tests-coverage

- name: Codecov Upload
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Test CLI
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
go test -coverprofile=go.txt -v ./...
go run main.go clean -r us-west-2
go run main.go version
- name: build & execute
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
echo "--------------------------------------------------"
go build -ldflags="-X 'github.com/karl-cardenas-coding/go-lambda-cleanup/cmd.VersionString=0.0.0'" -o=glc -v
Expand Down Expand Up @@ -79,9 +105,4 @@ jobs:
build-args: VERSION=${{steps.dependencies.outputs.VERSION}}
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository }}:test

- uses: actions/upload-artifact@v1
with:
name: test-results
path: go.txt
tags: ghcr.io/${{ github.repository }}:test
25 changes: 12 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Test & Validate
name: Branch Tests

on:
push:
branches-ignore: [ main ]
env:
GITHUB_TOKEN: ${{ github.token }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
LINT_VERSION: "1.25.1"


Expand All @@ -27,6 +25,9 @@ jobs:
uses: actions/checkout@v3

- name: Generate AWS region file
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws ec2 describe-regions --all-regions --region us-east-1 --query "Regions[].RegionName" --output text >> cmd/aws-regions.txt
Expand All @@ -35,24 +36,22 @@ jobs:
with:
args: -v


- name: Execute Go tests
run: go test -v ./...
run: make tests-coverage

- name: Test CLI
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
go get
go test -coverprofile=go.txt -v ./...
go run main.go clean -r us-west-2
go run main.go version
- name: build & execute
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
echo "--------------------------------------------------"
go build -ldflags="-X 'github.com/karl-cardenas-coding/go-lambda-cleanup/cmd.VersionString=0.0.0'" -o=glc -v
./glc clean -r us-west-2
- uses: actions/upload-artifact@v1
with:
name: test-results
path: go.txt
./glc clean -r us-west-2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ terraform.tfvars
lambda.zip
main
.DS_STORE
main
main
coverage.out
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) karl-cardenas-coding
# SPDX-License-Identifier: MIT

FROM golang:1.21.3-alpine3.18 as builder
FROM golang:1.21.4-alpine3.18 as builder

LABEL org.opencontainers.image.source="http://github.com/karl-cardenas-coding/go-lambda-cleanup"
LABEL org.opencontainers.image.description "A solution for removing previous versions of AWS Lambdas"
Expand Down
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
aws-regions.txt:
.PHONY: license

aws-regions:
aws ec2 describe-regions --region us-east-1 --all-regions --query "Regions[].RegionName" --output text > cmd/aws-regions.txt

license:
Expand All @@ -21,4 +23,18 @@ build: ## Build the binary file

tests: ## Run tests
@echo "Running tests"
go test -race -shuffle on ./...
go test -race ./...


tests-coverage: ## Start Go Test with code coverage
@echo "Running Go Tests with code coverage"
go test -race -shuffle on -cover -coverprofile=coverage.out -covermode=atomic ./...

view-coverage: ## View the code coverage
@echo "Viewing the code coverage"
go tool cover -html=coverage.out


nil: ## Check for nil errors
@echo "Checking for nil errors"
~/go/bin/nilaway ./...
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# go-lambda-cleanup
[![Main](https://github.com/karl-cardenas-coding/go-lambda-cleanup/actions/workflows/build.yml/badge.svg)](https://github.com/karl-cardenas-coding/go-lambda-cleanup/actions/workflows/build.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/karl-cardenas-coding/go-lambda-cleanup.svg)](https://pkg.go.dev/github.com/karl-cardenas-coding/go-lambda-cleanup)
[![Go version](https://img.shields.io/github/go-mod/go-version/karl-cardenas-coding/go-lambda-cleanup)](https://golang.org/dl/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![codecov](https://codecov.io/gh/karl-cardenas-coding/go-lambda-cleanup/graph/badge.svg?token=S8SY4ZA2ZA)](https://codecov.io/gh/karl-cardenas-coding/go-lambda-cleanup)
[![Go Report Card](https://goreportcard.com/badge/github.com/karl-cardenas-coding/go-lambda-cleanup)](https://goreportcard.com/report/github.com/karl-cardenas-coding/go-lambda-cleanup)


<p align="center">
<img src="/static/logo.png" alt="drawing" width="400"/>
Expand All @@ -18,7 +21,7 @@
go-lambda-cleanup is distributed as a single binary. [Download](https://github.com/karl-cardenas-coding/go-lambda-cleanup/releases) the binary and install go-lambda-cleanup in a directory in your system's [PATH](https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them). `/usr/local/bin` is the recommended path for UNIX/LINUX environments.

```shell
VERSION=2.0.9
VERSION=2.0.10
wget https://github.com/karl-cardenas-coding/go-lambda-cleanup/releases/download/v$VERSION/go-lambda-cleanup-v$VERSION-linux-amd64.zip
unzip go-lambda-cleanup-v$VERSION-linux-amd64.zip
sudo mv glc /usr/local/bin/
Expand All @@ -29,7 +32,7 @@ sudo mv glc /usr/local/bin/
go-lambda-cleanup is also available as a Docker image. Check out the [GitHub Packages](https://github.com/karl-cardenas-coding/go-lambda-cleanup/pkgs/container/go-lambda-cleanup) page for this repository to learn more about the available images.

```
VERSION=2.0.9
VERSION=2.0.10
docker pull ghcr.io/karl-cardenas-coding/go-lambda-cleanup:$VERSION
```

Expand Down Expand Up @@ -253,7 +256,7 @@ on:
# At 04:00 on every day
- cron: '0 04 * * *'
env:
VERSION: 2.0.9
VERSION: 2.0.10

jobs:
build:
Expand Down
Loading

0 comments on commit 8e67800

Please sign in to comment.