Skip to content

Commit

Permalink
ast tests, workflows, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
elkrammer committed Oct 10, 2024
1 parent 3c5ce84 commit f72d634
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 77 deletions.
90 changes: 43 additions & 47 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create Release on Push to Main
name: Build and Release

on:
push:
Expand All @@ -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 }}
File renamed without changes.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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?" 😩

Expand Down
4 changes: 3 additions & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 28 additions & 29 deletions ast/ast_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit f72d634

Please sign in to comment.