-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
201 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Create Release on Push to Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: release | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Wait | ||
run: sleep 600 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.23' | ||
|
||
- name: Build binaries | ||
run: | | ||
# Build for Linux | ||
GOOS=linux GOARCH=amd64 go build -o ./irule-validator | ||
# Build for macOS (Intel) | ||
GOOS=darwin GOARCH=amd64 go build -o ./irule-validator-macos-amd64 | ||
# Build for macOS (Apple Silicon) | ||
GOOS=darwin GOARCH=arm64 go build -o ./irule-validator-macos-arm64 | ||
# Build for Windows | ||
GOOS=windows GOARCH=amd64 go build -o ./irule-validator.exe | ||
- name: Get latest tag | ||
id: get_tag | ||
run: | | ||
# Check if any tags exist | ||
if [ -z "$(git tag)" ]; then | ||
echo "No tags found, creating initial tag v0.0.1" | ||
new_tag="v0.0.1" | ||
else | ||
# Get the latest tag | ||
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) | ||
echo "Latest tag: $latest_tag" | ||
# Increment the version (patch level) | ||
new_tag=$(echo $latest_tag | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | ||
fi | ||
echo "new_tag=$new_tag" >> $GITHUB_ENV | ||
- name: Create new tag | ||
run: | | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
git tag ${{ env.new_tag }} | ||
git push origin ${{ env.new_tag }} | ||
# Create GitHub release | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: ${{ env.new_tag }} | ||
files: | | ||
./irule-validator | ||
./irule-validator-macos-amd64 | ||
./irule-validator-macos-arm64 | ||
./irule-validator.exe | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.23' | ||
|
||
- name: Run tests | ||
run: | | ||
./run_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2024 elkrammer | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 📏 iRule-Validator | ||
|
||
Ever tried writing an F5 iRule and thought, "will this work?" only to have F5 | ||
respond with, "Nah, invalid expression on line 42?" 😩 | ||
|
||
Wouldn't it be nice to catch those errors in your iRules **before** they break production? | ||
Well, you're welcome! 🎁 | ||
|
||
Inspired by the awesome book [Writing an Interpreter in Go](https://interpreterbook.com), | ||
this project aims to parse F5 iRules with style and grace! 🦸 (Well, at least | ||
most of the time.) | ||
|
||
## 🚀 Usage | ||
|
||
```bash | ||
Usage of ./irule-validator: | ||
-d, --debug Debugging Mode | ||
-h, --help Show help message | ||
-p, --print-errors Print Errors | ||
|
||
If no parameter is specified it will run in quiet mode returning only | ||
the result. | ||
If a file name is specified, it will parse the provided file. | ||
If no file name is specified, it will go into REPL mode. | ||
|
||
Examples: | ||
./irule-validator http.irule # Parse http.irule and show only the result | ||
./irule-validator -p http.irule # Parse http.irule and print errors | ||
./irule-validator # Start REPL | ||
``` | ||
|
||
Pro Tip: When using this in a CI/CD pipeline, be sure to call it with `-p` to | ||
get those sweet error printouts you so desperately crave. | ||
|
||
## 🦄 Disclaimer | ||
|
||
Does it validate every possible command with perfect accuracy? Not quite. | ||
Full syntax validation is *hard*, and I've realized that F5 iRules are | ||
a bottomless pit of edge cases. 🕳️ | ||
|
||
Building a complete F5 iRule parser is like trying to solve a puzzle where | ||
the pieces keep changing shape. But hey, I already have a parser that | ||
covers most of the use cases I need and that's good enough for me! 🎉 | ||
|
||
## 🧑 Contributing | ||
|
||
PRs are welcome! 💥 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
package config | ||
|
||
import "github.com/spf13/pflag" | ||
import ( | ||
"fmt" | ||
"github.com/spf13/pflag" | ||
"os" | ||
) | ||
|
||
// App Config | ||
var DebugMode bool | ||
var PrintErrors bool | ||
|
||
// Setup program flags | ||
func SetupFlags() { | ||
// Define flags | ||
pflag.BoolVarP(&DebugMode, "debug", "d", false, "Run in debug mode") | ||
pflag.BoolVarP(&DebugMode, "debug", "d", false, "Debugging Mode") | ||
pflag.BoolVarP(&PrintErrors, "print-errors", "p", false, "Print Errors") | ||
|
||
pflag.Usage = func() { | ||
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) | ||
pflag.PrintDefaults() // prints the default flag options | ||
|
||
fmt.Fprintf(os.Stderr, ` | ||
If no parameter is specified it will run in quiet mode returning only | ||
the result. | ||
If a file name is specified, it will parse the provided file. | ||
If no file name is specified, it will go into REPL mode. | ||
Examples: | ||
./irule-validator http.irule # Parse http.irule and show only the result | ||
./irule-validator -p http.irule # Parse http.irule and print errors | ||
./irule-validator # Start REPL | ||
`) | ||
} | ||
|
||
// Manually check for the help flag before parsing | ||
help := pflag.BoolP("help", "h", false, "Show help message") | ||
|
||
pflag.Parse() | ||
|
||
if *help { | ||
pflag.Usage() | ||
os.Exit(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters