Skip to content

Commit

Permalink
merge dev to pre 22 (#308)
Browse files Browse the repository at this point in the history
* Update CONTRIBUTING.md (#303)

* fix(deps): update module github.com/xanzy/go-gitlab to v0.84.0 (#306)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/stretchr/testify to v1.8.4 (#302)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/aws/aws-sdk-go to v1.44.268 (#290)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* feat: Add support for NoOp lock implementation (#278)

Co-authored-by: duoctt <duoctt@vng.com.vn>

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Duoc Tran <51254650+duoctranth@users.noreply.github.com>
Co-authored-by: duoctt <duoctt@vng.com.vn>
  • Loading branch information
4 people committed Jun 1, 2023
1 parent 9efa3a7 commit e959bb4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ We strive to maintain a consistent coding style throughout the project. Please f

## Submitting a pull request
When you have made changes to the codebase that you would like to contribute back, please follow these steps:
1. Fork the repository and create a new branch from `main`.
1. Fork the repository and create a new branch from `develop`.
2. Make your changes and ensure that the code passes all tests.
3. Write tests for your changes, if applicable.
4. Update the documentation to reflect your changes, if applicable.
5. Submit a pull request to the `main` branch.
5. Submit a pull request to the `develop` branch.
We will review your pull request as soon as possible. Please be patient and open to feedback. We appreciate your contributions!

## Release Process
**NOTE: The default branch `@develop` is not guaranteed to be stable and you should always use published release versions in your testing and production.**

- All pull requests are merged to the default develop branch after initial unit tests and integration tests are passing and required code review requirements are met.
- We checkout a pre-release branch to prepare for an upcoming release.
- We checkout a pre-release branch to prepare for an upcoming release with the pattern `prerelease-0.1.xx`.
- We perform additional manual and automated tests in this branch to make sure there are no regressions.
- Once we are ready we tag the head of our release branch and perform a release on it.
- Tagged releases are published as actions and they are the most suitable to be used in production.
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ inputs:
description: Checkov version
required: false
default: '2.3.245'
disable-locking:
description: Disable locking
required: false
default: 'false'

outputs:
output:
Expand Down Expand Up @@ -150,6 +154,7 @@ runs:
env:
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
run: |
cd ${{ github.action_path }}
go build -o digger ./cmd/digger
Expand All @@ -162,6 +167,7 @@ runs:
env:
actionref: ${{ github.action_ref }}
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
id: digger
shell: bash
run: |
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require (
cloud.google.com/go/storage v1.30.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/data/aztables v1.0.1
github.com/aws/aws-sdk-go v1.44.266
github.com/aws/aws-sdk-go v1.44.268
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/caarlos0/env/v7 v7.1.0
github.com/google/go-github/v51 v51.0.0
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.8.3
github.com/xanzy/go-gitlab v0.83.0
github.com/stretchr/testify v1.8.4
github.com/xanzy/go-gitlab v0.84.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwF
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/aws/aws-sdk-go v1.44.266 h1:MWd775dcYf7NrwgcHLtlsIbWoWkX8p4vomfNHr88zH0=
github.com/aws/aws-sdk-go v1.44.266/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.268 h1:WoK20tlAvsvQzTcE6TajoprbXmTbcud6MjhErL4P/38=
github.com/aws/aws-sdk-go v1.44.268/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc=
github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand Down Expand Up @@ -116,8 +118,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEGw=
github.com/xanzy/go-gitlab v0.83.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
github.com/xanzy/go-gitlab v0.84.0 h1:PdpCaskQSgcVDsx21c6ikf8Rfyo7SNtFAJwP9PrbCFE=
github.com/xanzy/go-gitlab v0.84.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
Expand Down
24 changes: 23 additions & 1 deletion pkg/utils/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ type Lock interface {
GetLock(resource string) (*int, error)
}

type NoOpLock struct {
}

func (noOpLock *NoOpLock) Lock(transactionId int, resource string) (bool, error) {
return true, nil
}

func (noOpLock *NoOpLock) Unlock(resource string) (bool, error) {
return true, nil
}

func (noOpLock *NoOpLock) GetLock(resource string) (*int, error) {
return nil, nil
}

type ProjectLock interface {
Lock(prNumber int) (bool, error)
Unlock(prNumber int) (bool, error)
Expand Down Expand Up @@ -77,7 +92,9 @@ func (projectLock *ProjectLockImpl) Lock(prNumber int) (bool, error) {
return false, err
}

if lockAcquired {
_, isNoOpLock := projectLock.InternalLock.(*NoOpLock)

if lockAcquired && !isNoOpLock {
comment := "Project " + projectLock.projectId() + " has been locked by PR #" + strconv.Itoa(prNumber)
projectLock.CIService.PublishComment(prNumber, comment)
println("project " + projectLock.projectId() + " locked successfully. PR # " + strconv.Itoa(prNumber))
Expand Down Expand Up @@ -178,6 +195,11 @@ func GetLock() (Lock, error) {
awsRegion := strings.ToLower(os.Getenv("AWS_REGION"))
awsProfile := strings.ToLower(os.Getenv("AWS_PROFILE"))
lockProvider := strings.ToLower(os.Getenv("LOCK_PROVIDER"))
disableLocking := strings.ToLower(os.Getenv("DISABLE_LOCKING")) == "true"
if disableLocking {
log.Println("Using NoOp lock provider.")
return &NoOpLock{}, nil
}
if lockProvider == "" || lockProvider == "aws" {
log.Println("Using AWS lock provider.")
sess, err := session.NewSessionWithOptions(session.Options{
Expand Down

0 comments on commit e959bb4

Please sign in to comment.