Skip to content
Open
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
23 changes: 22 additions & 1 deletion .github/actions/create-draft-release-with-assets/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,37 @@ inputs:
asset-paths:
required: true
description: Comma-separated paths/globs passed to Get-ChildItem, e.g. "nugets/, powershellModules/, assets/"
dry-run:
required: false
default: 'false'
description: If true, skips creating the real draft release and only logs what would have been created.
outputs:
assets:
description: Comma-separated list of resolved asset file paths that were (or would be) attached
value: ${{ steps.create.outputs.assets }}
runs:
using: composite
steps:
- name: Create draft release and attach assets
id: create
shell: pwsh
run: |
$paths = '${{ inputs.asset-paths }}' -split ',' | ForEach-Object { $_.Trim() }
$assets = (Get-ChildItem -Path $paths -File -Recurse).FullName
Write-Output "Assets to attach: $assets"
Write-Output "Creating draft release for ${{ github.event.repository.name }} ${{ github.ref_name }} at commit ${{ github.sha }}"
gh release create ${{ github.ref_name }} $assets -d -n "<!-- RELEASE PENDING -->" -t "${{ github.ref_name }}"

if ('${{ inputs.dry-run }}' -eq 'true')
{
Write-Output "[dry-run] Skipping gh release create."
}
else
{
gh release create ${{ github.ref_name }} $assets -d -n "<!-- RELEASE PENDING -->" -t "${{ github.ref_name }}"
}

# -join keeps this on one line; $GITHUB_OUTPUT is line-based and a multi-line value would corrupt it.
$assetsJoined = $assets -join ','
echo "assets=$assetsJoined" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf-8 -Append
env:
GH_TOKEN: ${{ github.token }}
12 changes: 3 additions & 9 deletions .github/workflows/CI-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ on:
paths:
- '.github/actions/**'
jobs:
test-actions:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- name: Placeholder
run: echo "Placeholder for testing actions"
test-create-draft-release-with-assets:
uses: ./.github/workflows/test-create-draft-release-with-assets.yml

validate-action-tests:
# So we can add new tests without having to update branch protection rules
name: Validate action test results
needs: [test-actions]
needs: [test-create-draft-release-with-assets]
if: always()
runs-on: ubuntu-latest
defaults:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/test-create-draft-release-with-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test - create-draft-release-with-assets
on:
workflow_call:
jobs:
test-create-draft-release-with-assets:
name: dry run
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Prepare test assets
run: |
New-Item -ItemType Directory -Path test-assets/dir1/nested -Force | Out-Null
New-Item -ItemType Directory -Path test-assets/dir2 -Force | Out-Null
Set-Content -Path test-assets/dir1/file-a.txt -Value 'asset a'
Set-Content -Path test-assets/dir1/nested/file-b.txt -Value 'asset b'
Set-Content -Path test-assets/dir2/file-c.txt -Value 'asset c'
- name: Create draft release and attach assets
id: create
uses: ./.github/actions/create-draft-release-with-assets
with:
asset-paths: test-assets/dir1, test-assets/dir2
dry-run: true
- name: Verify resolved assets
run: |
$assets = '${{ steps.create.outputs.assets }}' -split ','
Write-Output "Resolved assets: $assets"

if ($assets.Count -ne 3)
{
throw "Expected 3 resolved assets (including the nested one), got $($assets.Count): $assets"
}

foreach ($expected in @('test-assets/dir1/file-a.txt', 'test-assets/dir1/nested/file-b.txt', 'test-assets/dir2/file-c.txt'))
{
$expectedFullPath = (Resolve-Path $expected).Path
if ($assets -notcontains $expectedFullPath)
{
throw "Expected assets to include '$expected', got: $assets"
}
}

Write-Output "OK"
- name: Verify no real release was created
run: |
gh release view '${{ github.ref_name }}' 2>$null
if ($LASTEXITCODE -eq 0)
{
throw "A real release for '${{ github.ref_name }}' exists even though dry-run was true."
}
Write-Output "OK: no real release exists for '${{ github.ref_name }}'"

# gh release view above is expected to fail (exit non-zero) when no release exists - reset
# $LASTEXITCODE so that the expected failure doesn't show the test run as failed.
$global:LASTEXITCODE = 0
env:
GH_TOKEN: ${{ github.token }}
- name: Clean up test assets
if: always()
run: Remove-Item -Path test-assets -Recurse -Force -ErrorAction SilentlyContinue
Loading