Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions .github/workflows/tk-compare.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Compare with Tanka

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:

permissions:
contents: read
pull-requests: write
issues: write

jobs:
compare:
name: Compare with Grafana Tanka
runs-on: ubuntu-latest
steps:
- name: Checkout rustanka
uses: actions/checkout@v4.1.4
with:
path: rustanka

- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0

- name: Install Grafana Tanka
run: |
TK_VERSION=$(curl -s https://api.github.com/repos/grafana/tanka/releases/latest | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')
curl -fSL -o "/usr/local/bin/tk" "https://github.com/grafana/tanka/releases/latest/download/tk-linux-amd64"
chmod +x /usr/local/bin/tk
tk --version

- name: Clone deployment_tools
# Note: deployment_tools is a Grafana internal repository
# This step will fail if you don't have access
# You can replace this with your own test repository
run: |
git clone --depth=1 https://github.com/grafana/deployment_tools.git
continue-on-error: true

- name: Check if deployment_tools exists
id: check_deployment_tools
run: |
if [ -d "deployment_tools" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "path=$(pwd)/deployment_tools" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Run comparison
if: steps.check_deployment_tools.outputs.exists == 'true'
id: run_comparison
working-directory: rustanka
run: |
set +e
make tk-compare-grafana DEPLOYMENT_TOOLS_PATH=${{ steps.check_deployment_tools.outputs.path }} TK_PATH=/usr/local/bin/tk > ../comparison-output.txt 2>&1
echo "exit_code=$?" >> $GITHUB_OUTPUT
cat ../comparison-output.txt
continue-on-error: true

- name: Prepare comment body
if: steps.check_deployment_tools.outputs.exists == 'true'
id: prepare_comment
run: |
if [ -f comparison-output.txt ]; then
echo "comment<<EOF" >> $GITHUB_OUTPUT
echo "## 🔬 Tanka Comparison Results" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "Comparing [Grafana Tanka](https://github.com/grafana/tanka) with rustanka:" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo '```' >> $GITHUB_OUTPUT
cat comparison-output.txt >> $GITHUB_OUTPUT
echo '```' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "comment=No comparison output available" >> $GITHUB_OUTPUT
fi

- name: Post PR comment
if: steps.check_deployment_tools.outputs.exists == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const comment = `${{ steps.prepare_comment.outputs.comment }}`;

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🔬 Tanka Comparison Results')
);

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}

- name: Post commit comment
if: steps.check_deployment_tools.outputs.exists == 'true' && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const comment = `${{ steps.prepare_comment.outputs.comment }}`;

await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: comment
});

- name: Skip comparison (no deployment_tools)
if: steps.check_deployment_tools.outputs.exists == 'false'
run: |
echo "Skipping comparison: deployment_tools repository not accessible"
echo "This is expected if you don't have access to Grafana's internal repositories"

- name: Upload comparison output
if: steps.check_deployment_tools.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: tk-compare-output
path: comparison-output.txt
if-no-files-found: ignore

- name: Upload workspace on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: tk-compare-workspace
path: rustanka/.tk-compare-workspace/
if-no-files-found: ignore

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ cache
jsonnet-cpp
jsonnet-sjsonnet
benchmarks

.tk-compare-workspace
92 changes: 91 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.PHONY: build-rtk build-tk-compare tk-compare-grafana help

.DEFAULT_GOAL := help

help:
@echo "Available targets:"
@echo " build-rtk - Build the rtk binary in release mode"
@echo " build-tk-compare - Build the tk-compare binary in release mode"
@echo " tk-compare-grafana - Run tk-compare against Grafana deployment_tools"
@echo ""
@echo "Environment variables for tk-compare-grafana:"
@echo " DEPLOYMENT_TOOLS_PATH - Path to grafana/deployment_tools repository (required)"
@echo " TK_PATH - Path to tk executable (required)"

build-rtk:
cargo build --release -p rtk

build-tk-compare:
cargo build --release -p tk-compare

tk-compare-grafana: build-rtk build-tk-compare
@if [ -z "$(DEPLOYMENT_TOOLS_PATH)" ]; then \
echo "Error: DEPLOYMENT_TOOLS_PATH is not set"; \
echo "Usage: make tk-compare-grafana DEPLOYMENT_TOOLS_PATH=/path/to/deployment_tools TK_PATH=/path/to/tk"; \
exit 1; \
fi
@if [ -z "$(TK_PATH)" ]; then \
echo "Error: TK_PATH is not set"; \
echo "Usage: make tk-compare-grafana DEPLOYMENT_TOOLS_PATH=/path/to/deployment_tools TK_PATH=/path/to/tk"; \
exit 1; \
fi
@if [ ! -d "$(DEPLOYMENT_TOOLS_PATH)" ]; then \
echo "Error: DEPLOYMENT_TOOLS_PATH does not exist: $(DEPLOYMENT_TOOLS_PATH)"; \
exit 1; \
fi
@if [ ! -x "$(TK_PATH)" ]; then \
echo "Error: TK_PATH is not executable: $(TK_PATH)"; \
exit 1; \
fi
DEPLOYMENT_TOOLS_PATH=$(DEPLOYMENT_TOOLS_PATH) TK_PATH=$(TK_PATH) ./target/release/tk-compare tk-compare-grafana.toml

1 change: 1 addition & 0 deletions cmds/jrsonnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version.workspace = true
workspace = true

[features]
default = ["exp-regex"]
experimental = [
"exp-preserve-order",
"exp-destruct",
Expand Down
15 changes: 15 additions & 0 deletions cmds/rtk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rtk"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "rtk"
path = "src/main.rs"

[dependencies]
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

Loading
Loading