Skip to content
Merged
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
256 changes: 195 additions & 61 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: false
default: ''

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

jobs:
test-resolve-vars:
name: Test Resolve Vars Action
Expand All @@ -16,8 +21,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Test resolve vars action
id: test-vars
- name: Run Variable Resolution
id: vars
uses: ./
with:
log_outputs: true
Expand All @@ -39,159 +44,288 @@ jobs:
- name: Print outputs
run: |
echo "=== DEBUG: Raw output ==="
echo "steps.test-vars.outputs.custom: '${{ steps.test-vars.outputs.custom }}'"
echo "steps.vars.outputs.custom: '${{ steps.vars.outputs.custom }}'"
echo "=========================="

- name: Verify outputs
- name: Verify custom outputs
run: |
# Check static variables
if [ "${{ fromJSON(steps.test-vars.outputs.custom).username }}" != "testuser" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).username }}" != "testuser" ]; then
echo "ERROR: username output doesn't match expected value"
exit 1
fi

if [ "${{ fromJSON(steps.test-vars.outputs.custom).environment }}" != "development" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).environment }}" != "development" ]; then
echo "ERROR: environment output doesn't match expected value"
exit 1
fi

# Check jinja variables
if [ "${{ fromJSON(steps.test-vars.outputs.custom).greeting }}" != "Hello, World!" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).greeting }}" != "Hello, World!" ]; then
echo "ERROR: greeting output doesn't match expected value"
echo "Expected: Hello, World!"
echo "Actual: ${{ fromJSON(steps.test-vars.outputs.custom).greeting }}"
echo "Actual: ${{ fromJSON(steps.vars.outputs.custom).greeting }}"
exit 1
fi

if [ "${{ fromJSON(steps.test-vars.outputs.custom).is_prod }}" != "False" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).is_prod }}" != "False" ]; then
echo "ERROR: is_prod output doesn't match expected value"
echo "Expected: False"
echo "Actual: ${{ fromJSON(steps.test-vars.outputs.custom).is_prod }}"
echo "Actual: ${{ fromJSON(steps.vars.outputs.custom).is_prod }}"
exit 1
fi

if [ "${{ fromJSON(steps.test-vars.outputs.custom).computed_name }}" != "testuser_development" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).computed_name }}" != "testuser_development" ]; then
echo "ERROR: computed_name output doesn't match expected value"
echo "Expected: testuser_development"
echo "Actual: ${{ fromJSON(steps.test-vars.outputs.custom).computed_name }}"
echo "Actual: ${{ fromJSON(steps.vars.outputs.custom).computed_name }}"
exit 1
fi

if [ "${{ fromJSON(steps.test-vars.outputs.custom).port_number }}" != "443" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).port_number }}" != "443" ]; then
echo "ERROR: port_number output doesn't match expected value"
echo "Expected: 443"
echo "Actual: ${{ fromJSON(steps.test-vars.outputs.custom).port_number }}"
echo "Actual: ${{ fromJSON(steps.vars.outputs.custom).port_number }}"
exit 1
fi

if [ "${{ fromJSON(steps.test-vars.outputs.custom).answer }}" != "42" ]; then
if [ "${{ fromJSON(steps.vars.outputs.custom).answer }}" != "42" ]; then
echo "ERROR: answer output doesn't match expected value"
echo "Expected: 42"
echo "Actual: ${{ fromJSON(steps.test-vars.outputs.custom).answer }}"
echo "Actual: ${{ fromJSON(steps.vars.outputs.custom).answer }}"
exit 1
fi

echo "✅ All tests passed!"
echo "Static outputs:"
echo " username: ${{ fromJSON(steps.test-vars.outputs.custom).username }}"
echo " environment: ${{ fromJSON(steps.test-vars.outputs.custom).environment }}"
echo " username: ${{ fromJSON(steps.vars.outputs.custom).username }}"
echo " environment: ${{ fromJSON(steps.vars.outputs.custom).environment }}"
echo "Jinja outputs:"
echo " greeting: ${{ fromJSON(steps.test-vars.outputs.custom).greeting }}"
echo " is_prod: ${{ fromJSON(steps.test-vars.outputs.custom).is_prod }}"
echo " computed_name: ${{ fromJSON(steps.test-vars.outputs.custom).computed_name }}"
echo " port_number: ${{ fromJSON(steps.test-vars.outputs.custom).port_number }}"

test-standard-ci-vars:
name: Test Standard CI Variables
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Test standard CI vars enabled
id: test-ci-vars
uses: ./
with:
log_outputs: true
pr: ${{ github.event.inputs.pr }}
static_inputs: |
custom_var=test_value
echo " greeting: ${{ fromJSON(steps.vars.outputs.custom).greeting }}"
echo " is_prod: ${{ fromJSON(steps.vars.outputs.custom).is_prod }}"
echo " computed_name: ${{ fromJSON(steps.vars.outputs.custom).computed_name }}"
echo " port_number: ${{ fromJSON(steps.vars.outputs.custom).port_number }}"

- name: Print CI variables output
run: |
echo "=== DEBUG: Standard CI Variables ==="
echo "All variables: ${{ steps.test-ci-vars.outputs.custom }}"
echo "Resolved repo: ${{ steps.test-ci-vars.outputs.resolved-repo-name-full }}"
echo "Resolved branch: ${{ steps.test-ci-vars.outputs.resolved-git-branch }}"
echo "PR number: ${{ steps.test-ci-vars.outputs.pr-number }}"
echo "Run ID: ${{ steps.test-ci-vars.outputs.run-id }}"
echo "Is PR: ${{ steps.test-ci-vars.outputs.is-pr }}"
echo "All variables: ${{ steps.vars.outputs.custom }}"
echo "Resolved repo: ${{ steps.vars.outputs.resolved-repo-name-full }}"
echo "Resolved branch: ${{ steps.vars.outputs.resolved-git-branch }}"
echo "PR number: ${{ steps.vars.outputs.pr-number }}"
echo "Run ID: ${{ steps.vars.outputs.run-id }}"
echo "Is PR: ${{ steps.vars.outputs.is-pr }}"
echo "=================================="

- name: Verify standard CI variables
run: |
# Check that standard CI variables are populated
if [ -z "${{ steps.test-ci-vars.outputs.resolved-repo-name-full }}" ]; then
if [ -z "${{ steps.vars.outputs.resolved-repo-name-full }}" ]; then
echo "ERROR: resolved-repo-name-full variable should be populated"
exit 1
fi

if [ -z "${{ steps.test-ci-vars.outputs.resolved-git-branch }}" ]; then
if [ -z "${{ steps.vars.outputs.resolved-git-branch }}" ]; then
echo "ERROR: resolved-git-branch variable should be populated"
exit 1
fi

if [ -z "${{ steps.test-ci-vars.outputs.resolved-repo-owner }}" ]; then
if [ -z "${{ steps.vars.outputs.resolved-repo-owner }}" ]; then
echo "ERROR: resolved-repo-owner variable should be populated"
exit 1
fi

if [ -z "${{ steps.test-ci-vars.outputs.resolved-repo-name }}" ]; then
if [ -z "${{ steps.vars.outputs.resolved-repo-name }}" ]; then
echo "ERROR: resolved-repo-name variable should be populated"
exit 1
fi

if [ -z "${{ steps.test-ci-vars.outputs.run-id }}" ]; then
if [ -z "${{ steps.vars.outputs.run-id }}" ]; then
echo "ERROR: run-id variable should be populated"
exit 1
fi

if [ -z "${{ steps.test-ci-vars.outputs.is-pr }}" ]; then
if [ -z "${{ steps.vars.outputs.is-pr }}" ]; then
echo "ERROR: is-pr variable should be populated"
exit 1
fi

# Verify resolved-repo-name-full matches expected format
if [ "${{ steps.test-ci-vars.outputs.resolved-repo-name-full }}" != "aaronsteers/resolve-ci-vars-action" ]; then
if [ "${{ steps.vars.outputs.resolved-repo-name-full }}" != "aaronsteers/resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name-full should be aaronsteers/resolve-ci-vars-action"
echo "Actual: ${{ steps.test-ci-vars.outputs.resolved-repo-name-full }}"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-name-full }}"
exit 1
fi

# Verify resolved-repo-owner matches expected value
if [ "${{ steps.test-ci-vars.outputs.resolved-repo-owner }}" != "aaronsteers" ]; then
if [ "${{ steps.vars.outputs.resolved-repo-owner }}" != "aaronsteers" ]; then
echo "ERROR: resolved-repo-owner should be aaronsteers"
echo "Actual: ${{ steps.test-ci-vars.outputs.resolved-repo-owner }}"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-owner }}"
exit 1
fi

# Verify resolved-repo-name matches expected value
if [ "${{ steps.test-ci-vars.outputs.resolved-repo-name }}" != "resolve-ci-vars-action" ]; then
if [ "${{ steps.vars.outputs.resolved-repo-name }}" != "resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name should be resolve-ci-vars-action"
echo "Actual: ${{ steps.test-ci-vars.outputs.resolved-repo-name }}"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-name }}"
exit 1
fi

# Verify is-pr is false for non-PR events (this test runs on pull_request so should be true)
if [ "${{ steps.test-ci-vars.outputs.is-pr }}" != "true" ]; then
if [ "${{ steps.vars.outputs.is-pr }}" != "true" ]; then
echo "ERROR: is-pr should be true for pull_request events"
echo "Actual: ${{ steps.test-ci-vars.outputs.is-pr }}"
echo "Actual: ${{ steps.vars.outputs.is-pr }}"
exit 1
fi

echo "✅ Standard CI variables test passed!"

- name: Verify standard CI variables
run: |
# Check that standard CI variables are populated
if [ -z "${{ steps.vars.outputs.resolved-repo-name-full }}" ]; then
echo "ERROR: resolved-repo-name-full variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars.outputs.resolved-git-branch }}" ]; then
echo "ERROR: resolved-git-branch variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars.outputs.resolved-repo-owner }}" ]; then
echo "ERROR: resolved-repo-owner variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars.outputs.resolved-repo-name }}" ]; then
echo "ERROR: resolved-repo-name variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars.outputs.run-id }}" ]; then
echo "ERROR: run-id variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars.outputs.is-pr }}" ]; then
echo "ERROR: is-pr variable should be populated"
exit 1
fi

# Verify resolved-repo-name-full matches expected format
if [ "${{ steps.vars.outputs.resolved-repo-name-full }}" != "aaronsteers/resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name-full should be aaronsteers/resolve-ci-vars-action"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-name-full }}"
exit 1
fi

# Verify resolved-repo-owner matches expected value
if [ "${{ steps.vars.outputs.resolved-repo-owner }}" != "aaronsteers" ]; then
echo "ERROR: resolved-repo-owner should be aaronsteers"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-owner }}"
exit 1
fi

# Verify resolved-repo-name matches expected value
if [ "${{ steps.vars.outputs.resolved-repo-name }}" != "resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name should be resolve-ci-vars-action"
echo "Actual: ${{ steps.vars.outputs.resolved-repo-name }}"
exit 1
fi

# Verify is-pr is false for non-PR events (this test runs on pull_request so should be true)
if [ "${{ steps.vars.outputs.is-pr }}" != "true" ]; then
echo "ERROR: is-pr should be true for pull_request events"
echo "Actual: ${{ steps.vars.outputs.is-pr }}"
exit 1
fi

echo "✅ Standard CI variables test passed!"

- name: Run Variable Resolution (Explicit PR 5)
id: vars-pr5
uses: ./
with:
pr: 5
log_outputs: true
static_inputs: |
username=testuser
environment=development

# Jinja2 inputs to evaluate:
# These are intentionally nonsensical, but they demonstrate the syntax
# and they test the tool's ability to evaluate dynamic jinja2 expressions.
jinja_inputs: |
greeting='Hello, ' + 'World!'
is_prod=False
computed_name='${{ 'testuser' }}' + '_' + '${{ 'development' }}'
port_number=8080 if 'true' == 'false' else 443
answer=42

- name: Verify standard CI variables (explicit PR)
run: |
# Check that standard CI variables are populated
if [ "${{ steps.vars-pr5.outputs.pr-number }}" != "5" ]; then
echo "ERROR: pr-number should be 5, not '${{ steps.vars-pr5.outputs.pr-number }}'"
exit 1
fi

if [ -z "${{ steps.vars-pr5.outputs.resolved-repo-name-full }}" ]; then
echo "ERROR: resolved-repo-name-full variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars-pr5.outputs.resolved-git-branch }}" ]; then
echo "ERROR: resolved-git-branch variable should be populated"
exit 1
fi

# Check that custom variables are still included
if [ "${{ fromJSON(steps.test-ci-vars.outputs.custom).custom_var }}" != "test_value" ]; then
echo "ERROR: custom_var should still be included with standard CI vars"
if [ -z "${{ steps.vars-pr5.outputs.resolved-repo-owner }}" ]; then
echo "ERROR: resolved-repo-owner variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars-pr5.outputs.resolved-repo-name }}" ]; then
echo "ERROR: resolved-repo-name variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars-pr5.outputs.run-id }}" ]; then
echo "ERROR: run-id variable should be populated"
exit 1
fi

if [ -z "${{ steps.vars-pr5.outputs.is-pr }}" ]; then
echo "ERROR: is-pr variable should be populated"
exit 1
fi

# Verify resolved-repo-name-full matches expected format
if [ "${{ steps.vars-pr5.outputs.resolved-repo-name-full }}" != "aaronsteers/resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name-full should be aaronsteers/resolve-ci-vars-action"
echo "Actual: ${{ steps.vars-pr5.outputs.resolved-repo-name-full }}"
exit 1
fi

# Verify resolved-repo-owner matches expected value
if [ "${{ steps.vars-pr5.outputs.resolved-repo-owner }}" != "aaronsteers" ]; then
echo "ERROR: resolved-repo-owner should be aaronsteers"
echo "Actual: ${{ steps.vars-pr5.outputs.resolved-repo-owner }}"
exit 1
fi

# Verify resolved-repo-name matches expected value
if [ "${{ steps.vars-pr5.outputs.resolved-repo-name }}" != "resolve-ci-vars-action" ]; then
echo "ERROR: resolved-repo-name should be resolve-ci-vars-action"
echo "Actual: ${{ steps.vars-pr5.outputs.resolved-repo-name }}"
exit 1
fi

# Verify is-pr is false for non-PR events (this test runs on pull_request so should be true)
if [ "${{ steps.vars-pr5.outputs.is-pr }}" != "true" ]; then
echo "ERROR: is-pr should be true for pull_request events"
echo "Actual: ${{ steps.vars-pr5.outputs.is-pr }}"
exit 1
fi

Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,14 @@ The action automatically resolves common CI variables from GitHub context, elimi
| `resolved-repo-name` | Repository name (e.g. `my-repo`) | `airbyte` |
| `resolved-repo-owner` | Repository owner (user or org) | `airbytehq` |
| `resolved-repo-name-full` | Owner + name (e.g. `myorg/my-repo`) | `airbytehq/airbyte` |
| `resolved-git-branch-url` | URL to the branch in GitHub | `https://github.com/airbytehq/airbyte/tree/feature/new-connector` |
| `resolved-git-commit-url` | URL to the commit in GitHub | `https://github.com/airbytehq/airbyte/commit/abc123...` |
| **PR Source Variables (for PR workflows)** |
| `pr-source-git-ref` | Git ref of the source (PR head) | `refs/heads/feature/new-connector` |
| `pr-source-git-branch` | Branch name of the source | `feature/new-connector` |
| `pr-source-git-sha` | SHA of the source commit | `abc123...` |
| `pr-source-repo-name` | Source repo name | `airbyte` |
| `pr-source-repo-owner` | Source repo owner | `contributor` |
| `pr-source-repo-name-full` | Full source repo name (owner/name) | `contributor/airbyte` |
| `pr-source-git-branch-url` | URL to the source branch | `https://github.com/contributor/airbyte/tree/feature/new-connector` |
| `pr-source-git-commit-url` | URL to the source commit | `https://github.com/contributor/airbyte/commit/abc123...` |
| `pr-source-is-fork` | Whether the source repo is a fork | `true` |
| `pr-source-repo-is-fork` | Whether the source repo is a fork of the target repo | `true` |
| **PR Target Variables (for PR workflows)** |
| `pr-target-git-ref` | Git ref of the target (PR base) | `refs/heads/main` |
| `pr-target-git-branch` | Branch name of the target | `main` |
Expand All @@ -115,8 +111,6 @@ The action automatically resolves common CI variables from GitHub context, elimi
| `pr-target-repo-name` | Target repo name | `airbyte` |
| `pr-target-repo-owner` | Target repo owner | `airbytehq` |
| `pr-target-repo-name-full` | Full target repo name (owner/name) | `airbytehq/airbyte` |
| `pr-target-git-branch-url` | URL to the target branch | `https://github.com/airbytehq/airbyte/tree/main` |
| `pr-target-git-commit-url` | URL to the target commit | `https://github.com/airbytehq/airbyte/commit/def456...` |
| **Additional Resolved Metadata** |
| `pr-number` | Pull request number (if applicable) | `12345` |
| `pr-url` | URL to the pull request | `https://github.com/airbytehq/airbyte/pull/12345` |
Expand Down
Loading