diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f426576..6f111db 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Create Release on Push to Main +name: Build and Release on: push: @@ -12,62 +12,58 @@ concurrency: jobs: build: runs-on: ubuntu-latest - + permissions: + contents: write + strategy: + matrix: + include: + - goos: windows + goarch: amd64 + - goos: darwin + goarch: amd64 + - goos: darwin + goarch: arm64 + - goos: linux + goarch: amd64 steps: - name: Checkout code - uses: actions/checkout@v3 - - - name: Wait - run: sleep 600 - + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: '1.23' - - - name: Build binaries + go-version: 1.23 + - name: Build 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 - + BINARY_NAME="irule-validator-${{ matrix.goos }}-${{ matrix.goarch }}" + if [ "${{ matrix.goos }}" = "windows" ]; then + BINARY_NAME="${BINARY_NAME}.exe" + fi + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ${BINARY_NAME} - 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 + git fetch --tags + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "v0.0.0") + new_tag=$(echo $latest_tag | awk -F. -v OFS=. '{$NF = $NF + 1;} 1') echo "new_tag=$new_tag" >> $GITHUB_ENV + echo "previous_tag=$latest_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 + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 with: - tag_name: ${{ env.new_tag }} - files: | - ./irule-validator - ./irule-validator-macos-amd64 - ./irule-validator-macos-arm64 - ./irule-validator.exe + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: irule-validator-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} + tag: ${{ env.new_tag }} + make_latest: true + prerelease: false + body: "Release ${{ env.new_tag }}" + + - name: Delete previous release + if: env.previous_tag != '' + run: | + latest_release=$(gh release list -L 1 | cut -f1 || echo "v0.0.0") + if [ "$latest_release" != "v0.0.0" ]; then + gh release delete $latest_release -y || true + fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yaml similarity index 100% rename from .github/workflows/run-tests.yml rename to .github/workflows/run-tests.yaml diff --git a/README.md b/README.md index b4604fb..e3c6c24 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # 📏 iRule-Validator +![Static Badge](https://img.shields.io/badge/build-passing-elk) +![GitHub Release](https://img.shields.io/github/v/release/elkrammer/irule-validator) +![Static Badge](https://img.shields.io/badge/license-MIT-blue?) + Ever tried writing an F5 iRule and thought, "will this work?" only to have F5 respond with, "Nah, invalid expression on line 42?" 😩 diff --git a/ast/ast.go b/ast/ast.go index a245f96..72bf608 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -222,7 +222,9 @@ type StringLiteral struct { func (sl *StringLiteral) expressionNode() {} func (sl *StringLiteral) TokenLiteral() string { return sl.Token.Literal } -func (sl *StringLiteral) String() string { return sl.Token.Literal } +func (sl *StringLiteral) String() string { + return `"` + sl.Value + `"` +} // BLOCKS type BlockStatement struct { diff --git a/ast/ast_test.go b/ast/ast_test.go index 9d1242d..1e50090 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -1,34 +1,33 @@ package ast import ( -// "testing" - -// "github.com/elkrammer/irule-validator/token" + "github.com/elkrammer/irule-validator/token" + "testing" ) -// func TestString(t *testing.T) { -// program := &Program{ -// Statements: []Statement{ -// &ExpressionStatement{ -// Expression: &CallExpression{ -// Function: &Identifier{ -// Token: token.Token{Type: token.IDENT, Literal: "puts"}, -// Value: "puts", -// }, -// Arguments: []Expression{ -// &StringLiteral{ -// Token: token.Token{Type: token.STRING, Literal: "Hello, world!"}, -// Value: "Hello, world!", -// }, -// }, -// }, -// }, -// }, -// } -// -// expected := "puts \"Hello, world!\";" -// -// if program.String() != expected { -// t.Errorf("program.String() wrong. Got=%q, Expected=%q", program.String(), expected) -// } -// } +func TestString(t *testing.T) { + program := &Program{ + Statements: []Statement{ + &ExpressionStatement{ + Expression: &CallExpression{ + Function: &Identifier{ + Token: token.Token{Type: token.IDENT, Literal: "puts"}, + Value: "puts", + }, + Arguments: []Expression{ + &StringLiteral{ + Token: token.Token{Type: token.STRING, Literal: "Hello, world!"}, + Value: "Hello, world!", + }, + }, + }, + }, + }, + } + + expected := `puts("Hello, world!")` + + if program.String() != expected { + t.Errorf("program.String() wrong. Got=%q, Expected=%q", program.String(), expected) + } +}