Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nawaz1991 authored and Muhammad Nawaz committed Oct 23, 2023
1 parent a44a0c1 commit 3ad7d9a
Show file tree
Hide file tree
Showing 21 changed files with 845 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
return {
default = {
verbose = true,
coverage = false,
output = "gtest",
},
}
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.lua]
indent_style = space
indent_size = 2

[kong/templates/nginx*]
indent_style = space
indent_size = 4

[*.template]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
52 changes: 52 additions & 0 deletions .github/workflows/license-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Apply EE License and Copyright"
on: [create]

env:
SENDER: ${{ github.event.sender.login }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: "chore(license): EE License and Copyright"

jobs:
license_checker:
if: contains(
fromJson('[
"kong",
"konghq-cx"
]'),
github.event.repository.owner.login
) &&
github.event.ref_type == 'branch' &&
github.event.repository.full_name != 'kong/kong-plugin' &&
github.event.repository.private == true
runs-on: ubuntu-latest
name: Apply EE License and Copyright
steps:
- name: Checkout
uses: actions/checkout@v3
- name: License and Copyright Checker
run: |
PR_BRANCH="chore/$GITHUB_REF_NAME-license-updated"
git config --global user.name "${{ env.SENDER }}"
git config --global user.email "${{ env.SENDER }}@users.noreply.github.com"
git fetch origin
git checkout -b "$PR_BRANCH"
.license-scripts/license-checker.sh
git commit -am "${{ env.MESSAGE }}"
git push origin "$PR_BRANCH"
gh pr create --title "${{ env.MESSAGE }}" --body "" --base "$GITHUB_REF_NAME"
cleanup:
if: ${{ always() && github.event.repository.full_name != 'kong/kong-plugin'}}
runs-on: ubuntu-latest
needs: license_checker
name: Cleanup
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cleanup
run: |
git config --global user.name "${{ env.SENDER }}"
git config --global user.email "${{ env.SENDER }}@users.noreply.github.com"
git switch "$GITHUB_REF_NAME"
rm -r .github/workflows/license-checker.yml .license-scripts
git commit -am "${{ env.MESSAGE }} Action Cleanup"
git push
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

concurrency:
group: ${{ github.workflow }} ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
pull_request: {}
push:
branches:
- master

jobs:
luacheck:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: LuaCheck linter
uses: lunarmodules/luacheck@master
86 changes: 86 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Test"

concurrency:
group: ${{ github.workflow }} ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
pull_request: {}
push:
branches:
- master
schedule:
- cron: '0 0 * * *' # every day at midnight, to test against nightlies

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
kongVersion:
- "2.8.x"
- "3.0.x"
- "dev"
- "3.0.0.x"
- "dev-ee"

steps:
- uses: actions/checkout@v3

- uses: Kong/kong-license@master
# this step is only for Kong Inc internal uses, external users should
# use the 'license' parameter of the kong-pongo action.
with:
password: ${{ secrets.PULP_PASSWORD }}

- uses: Kong/kong-pongo-action@v1
with:
pongo_version: master
kong_version: ${{ matrix.kongVersion }}
# Non-Kong-Inc users should provide their Enterprise license as a secret
# if testing against Enterprise versions.
# Kong Inc users should use the `Kong/kong-license` action
license: ${{ secrets.KONG_LICENSE_DATA }}


# the following 3 entries are only for Kong Inc internal use to test against
# the private Kong Enterprise development images, external users should
# delete these.
enterprise_nightly_docker_username: ${{ secrets.GHA_DOCKERHUB_PULL_USER }}
enterprise_nightly_docker_password: ${{ secrets.GHA_KONG_ORG_DOCKERHUB_PUBLIC_TOKEN }}
# github token with permissions to clone the kong-ee repo
github_token: ${{ secrets.GHA_KONG_BOT_READ_TOKEN }}

- run: pongo run -- --coverage




# Optional upload of coverage data,
# just ugly, something to fix...
- uses: leafo/gh-actions-lua@v10
if: success()
- uses: leafo/gh-actions-luarocks@v4
if: success()
- name: Report test coverage
if: success()
continue-on-error: true
run: |
luarocks install luacov-coveralls
# hack: luacov config file has a path for inside the pongo container
# rewrite those to the local location in GHA
if [ -f .luacov ]; then
cp .luacov .luacov_backup
cat .luacov_backup | sed 's/\/kong-plugin\/luacov./luacov./' > .luacov
fi
rm *.report.out
luacov-coveralls
#luacov-coveralls --output coveralls.out
# undo the hack
if [ -f .luacov_backup ]; then
mv .luacov_backup .luacov
fi
env:
COVERALLS_REPO_TOKEN: ${{ github.token }}
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# servroot is typically the nginx/Kong workingdirectory when testing
servroot

# packed distribution format for LuaRocks
*.rock
# exclude Pongo shell history
.pongo/.ash_history
.pongo/.bash_history
# exclude LuaCov statistics file
luacov.stats.out
# exclude LuaCov report
luacov.report.out
# exclude Pongo containerid file
.containerid
.idea
2 changes: 2 additions & 0 deletions .license-scripts/COPYRIGHT-HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Copyright (c) 2023 Muhammad Nawaz
-- Licensed under the MIT License. See LICENSE file for more information.
21 changes: 21 additions & 0 deletions .license-scripts/EE-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Muhammad Nawaz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 49 additions & 0 deletions .license-scripts/license-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
#
# * check that all lua files have the COPYRIGHT's sha in the header
# * if not, add the content of ./COPYRIGHT-HEADER to each file
#
# * replace the LICENSE file from the root directory (if it exists)
# with the content of ./EE-LICENSE (otherwise create it).
#

LOCAL_PATH=$(dirname $(realpath $0))

function add_copyright {
echo "Adding copyright headers"

local ret=0
local count=0
local header="$LOCAL_PATH/COPYRIGHT-HEADER"
local sha=$(shasum $header | cut -f1 -d' ')
local eol="-- [ END OF LICENSE $sha ]"
for f in $(find "." -type f -name "*.lua"); do
grep -Fq "$sha" $f || {
ret=1
cat "$header" <(echo "$eol") <(echo) $f >${f}.new
mv $f.new $f
((count++))
}
done

[[ $ret -ne 0 ]] &&
echo "Added headers to $count files."
}

function replace_license {
echo "Replacing license"

cat "$LOCAL_PATH/EE-LICENSE" > "$LOCAL_PATH/../LICENSE" || return 1
}

main() {

add_copyright
replace_license
RET=$?

return $RET

}

main
45 changes: 45 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Configuration file for LuaCheck
-- see: https://luacheck.readthedocs.io/en/stable/
--
-- To run do: `luacheck .` from the repo

std = "ngx_lua"
unused_args = false
redefined = false
max_line_length = false


globals = {
"_KONG",
"kong",
"ngx.IS_CLI",
}


not_globals = {
"string.len",
"table.getn",
}


ignore = {
"6.", -- ignore whitespace warnings
}


include_files = {
"**/*.lua",
"*.rockspec",
".busted",
".luacheckrc",
}

exclude_files = {
--"spec/fixtures/invalid-module.lua",
--"spec-old-api/fixtures/invalid-module.lua",
}


files["spec/**/*.lua"] = {
std = "ngx_lua+busted",
}
7 changes: 7 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include = {
"%/kong%-plugin%/kong%/.+$",
}

statsfile = "/kong-plugin/luacov.stats.out"
reportfile = "/kong-plugin/luacov.report.out"
runreport = true
3 changes: 3 additions & 0 deletions .pongo/pongorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--postgres
--no-cassandra

36 changes: 36 additions & 0 deletions .travis.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# rename to ".travis.yml" to enable this file for Travis CI

dist: focal

jobs:
include:
# to add Kong Enterprise releases, check the Pongo docs
- name: Kong CE 2.3.x
env: KONG_VERSION=2.3.x
- name: Kong CE 2.4.x
env: KONG_VERSION=2.4.x
- name: Kong CE master
env: KONG_VERSION=nightly POSTGRES=latest CASSANDRA=latest
- name: Enterprise 2.3.3.x
env: KONG_VERSION=2.3.3.x
- name: Enterprise 2.4.1.x
env: KONG_VERSION=2.4.1.x
- name: Nightly EE-master
env: KONG_VERSION=nightly-ee POSTGRES=latest CASSANDRA=latest

install:
- git clone --single-branch https://github.com/Kong/kong-pongo ../kong-pongo
- "../kong-pongo/pongo.sh up"
- "../kong-pongo/pongo.sh build"

script:
- "../kong-pongo/pongo.sh lint"
- "../kong-pongo/pongo.sh run"

notifications:
slack:
if: branch = master AND type != pull_request
on_success: change
on_failure: always
rooms:
secure: HdpUy77gMJEapyYOnKBqYeWFALG771KnLzUzbM5Et8br7RNrUTvA4fZ+paoLnIWU+0Sb+8A8/tRxBvPpxnVJFYZReQT4oBhX+wVTYbVr4i+UKfIDrU4DJ2nj3lHTa5t/dX7WZttBwFB8fuVugceWVF95DZCC9ll38d646+27wYydamu2hgCBs+PI4+J6msmFMC0T2vMr3A+B9reyiWQ+KG+E5U7mcmgMZ/xh10pBinPA7nXe0N4z50hR/ooHukFzMHDCyfVIKox9z9WQzS3SUI+Wxj6dts+dDVmVfTlM4XUM9e2MMDkBZgvQIedrjaR5pgdTl2xTWrMuMeeKbuimGa7FGD5rirgBg5gkP9LG1aSzJLP0lp4ldogTX+9VVaDE5N+ACKcR/10U3CskJYuOXx4cp0ub+TDIfe34NxgBe9PmTmJbTtRBgZ0sNVfZqfCmDYeCMTTyA+zug+XkPI+lQ56QqgFg4Hxohr+EsCQcQzA2YI9QUw0fIZPKyWQ91neE/ytF4xvNM8YI0yuLLgRYbbcvu6Tn4q0rwJkIdjh9eExD9ddsgTmENVN0KEYMj/Rk3WUJi6k7MDcSmxaBLC9REObgddyGM4hgXtbLGBAnJaDBHTaDBetTmrae2PAiZs478P4l5X1TzlZZMYVLlpVukpDJPzH6NBXZgiYjkyFipVc=
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
Loading

0 comments on commit 3ad7d9a

Please sign in to comment.