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
26 changes: 26 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Branch
on:
pull_request:
branches:
- main
- release/**
types: [opened, synchronize, reopened]
push:
branches:
- main
- release/v*
paths-ignore:
- '.github/**'
- 'docs/**'
- 'examples/**'
- 'test/**'
- 'README.md'

permissions:
contents: write
actions: write

jobs:
github-action:
uses: cloudposse/.github/.github/workflows/shared-github-action.yml@main
secrets: inherit
193 changes: 193 additions & 0 deletions .github/workflows/test-positive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
name: Test Action

on:
workflow_dispatch:
inputs:
test_tag:
description: "Tag to test with"
required: false
default: "test-v1.0.0"

jobs:
test-lightweight-tag:
runs-on: ubuntu-latest
env:
TAG_REF: test-lightweight-v1.0.0
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create test lightweight tag
run: |
git tag test-lightweight-v1.0.0
git push origin test-lightweight-v1.0.0

- name: Test action with lightweight tag
id: test_lightweight
uses: ./
with:
tag_ref: ${{ env.TAG_REF }}
branch: test-branch-lightweight-${{ env.TAG_REF }}
update_if_exists: "false"

- name: Verify outputs
run: |
echo "Branch name: ${{ steps.test_lightweight.outputs.branch_name }}"
echo "Branch URL: ${{ steps.test_lightweight.outputs.branch_url }}"
echo "Created: ${{ steps.test_lightweight.outputs.created }}"

# Verify branch was created
if [ "${{ steps.test_lightweight.outputs.created }}" != "true" ]; then
echo " Expected created=true for new branch"
exit 1
fi

if [ "${{ steps.test_lightweight.outputs.branch_name }}" != "test-branch-lightweight-${{ env.TAG_REF }}" ]; then
echo " Unexpected branch name"
exit 1
fi

test-annotated-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create test annotated tag
run: |
git config user.name "Test Bot"
git config user.email "[email protected]"
git tag -a test-annotated-v1.0.0 -m "Test annotated tag"
git push origin test-annotated-v1.0.0

- name: Test action with annotated tag
id: test_annotated
uses: ./
with:
tag_ref: test-annotated-v1.0.0
branch: test-branch-annotated

- name: Verify outputs
run: |
echo "Branch name: ${{ steps.test_annotated.outputs.branch_name }}"
echo "Branch URL: ${{ steps.test_annotated.outputs.branch_url }}"
echo "Created: ${{ steps.test_annotated.outputs.created }}"

test-update-existing:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create test tag
run: |
git config user.name "Test Bot"
git config user.email "[email protected]"
git tag test-update-v1.0.0
git push origin test-update-v1.0.0

- name: First run - create branch
id: first_run
uses: ./
with:
tag_ref: test-update-v1.0.0
branch: test-branch-update

- name: Second run - update branch
id: second_run
uses: ./
with:
tag_ref: test-update-v1.0.0
branch: test-branch-update
update_if_exists: "true"

- name: Third run - should update (update_if_exists=true)
id: third_run
uses: ./
with:
tag_ref: test-update-v1.0.0
branch: test-branch-update
update_if_exists: "true"

- name: Verify behavior
run: |
# First run should create
if [ "${{ steps.first_run.outputs.created }}" != "true" ]; then
echo " First run should have created branch"
exit 1
fi

# Second run should skip
if [ "${{ steps.second_run.outputs.created }}" != "false" ]; then
echo " Second run should not have created branch"
exit 1
fi

# Third run should update (not create)
if [ "${{ steps.third_run.outputs.created }}" != "false" ]; then
echo " Third run should not have created branch (update only)"
exit 1
fi

test-error-handling:
runs-on: ubuntu-latest
env:
TAG_REF: non-existent-tag-v999.999.999
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test with non-existent tag
id: test_missing_tag
uses: ./
continue-on-error: true
with:
tag_ref: ${{ env.TAG_REF }}
branch: test-error-${{ env.TAG_REF }}

- name: Verify error handling
run: |
if [ "${{ steps.test_missing_tag.outcome }}" != "failure" ]; then
echo " Action should have failed with non-existent tag"
exit 1
fi
echo "Error handling works correctly"

cleanup:
runs-on: ubuntu-latest
needs:
[
test-lightweight-tag,
test-annotated-tag,
test-update-existing,
test-error-handling,
]
if: always()
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cleanup test tags and branches
run: |
git config user.name "Test Bot"
git config user.email "[email protected]"

# Delete test tags
git push --delete origin test-lightweight-v1.0.0 || true
git push --delete origin test-annotated-v1.0.0 || true
git push --delete origin test-update-v1.0.0 || true

# Delete test branches
git push --delete origin [email protected] || true
git push --delete origin [email protected] || true
git push --delete origin [email protected] || true
Loading
Loading