Skip to content

Commit a6c7b88

Browse files
🌟 [Major]: Add Path parameter to replace WorkingDirectory (#3)
## Description This pull request includes changes to the `README.md` and `action.yml` files to update the artifact download process and correct the path usage. This includes the renaming of the `WorkingDirectory` input to `Path`, updating the `README.md` to reflect this change, and modifying the script path in the `action.yml`. Updates to artifact download process: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L12-R17): Renamed `WorkingDirectory` input to `Path` and updated the description to reflect the new input name. * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L9-R11): Renamed `WorkingDirectory` input to `Path` and updated the description accordingly. [[1]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L9-R11) [[2]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R28-R30) Path usage correction: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L42-R51): Modified the script path from backslashes to forward slashes for compatibility. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [x] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 5c0936d commit a6c7b88

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ As an example, terraform plans can be uploaded as artifacts in a PR CI workflow
99

1010
| Name | Description | Required | Default |
1111
| - | - | - | - |
12-
| `WorkingDirectory` | The working directory where the artifact will be downloaded to. Default is the root of the repository. | No | |
12+
| `Path` | The path to the artifact to download. | No | |
1313
| `WorkflowID` | The filename or ID of the workflow to download the artifact from. You must provide either `WorkflowID` or `WorkflowRunID`. | No | '' |
1414
| `WorkflowRunID` | The ID of the workflow run where the artifact will be download from. You must provide either `WorkflowID` or `WorkflowRunID`. | No | '' |
15-
| `ArtifactName` | Name of the artifact to download. If unspecified, all artifacts for the run are downloaded. | Yes | |
16-
| `GITHUB_TOKEN` | The GitHub token used to authenticate with the GitHub API. | Yes | |
15+
| `ArtifactName` | Name of the artifact to download. If unspecified, all artifacts for the run are downloaded. | Yes | |
16+
| `GITHUB_TOKEN` | The GitHub token used to authenticate with the GitHub API. | Yes | |
17+
| `WorkingDirectory` | The working directory where the artifact will be downloaded to. Default is the root of the repository. | No | `${{ github.workspace }}` |
1718

1819
### Outputs
1920

action.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ branding:
66
color: white
77

88
inputs:
9-
WorkingDirectory:
10-
description: The working directory where the artifact will be downloaded to. Default is the root of the repository.
9+
Path:
10+
description: The path to the artifact to download.
1111
required: false
1212
WorkflowID:
1313
description: The filename or ID of the workflow to download the artifact from. You must provide either `WorkflowID` or `WorkflowRunID`.
@@ -25,6 +25,9 @@ inputs:
2525
GITHUB_TOKEN:
2626
description: The GitHub token used to authenticate with the GitHub API.
2727
required: true
28+
WorkingDirectory:
29+
description: The working directory where the artifact will be downloaded to. Default is the root of the repository.
30+
required: false
2831

2932
runs:
3033
using: composite
@@ -35,16 +38,17 @@ runs:
3538
working-directory: ${{ inputs.WorkingDirectory }}
3639
env:
3740
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
38-
GITHUB_ACTION_INPUT_WorkflowID: ${{ inputs.WorkflowID }}
39-
GITHUB_ACTION_INPUT_WorkflowRunID: ${{ inputs.WorkflowRunID }}
41+
PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_Path: ${{ inputs.Path }}
42+
PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowID: ${{ inputs.WorkflowID }}
43+
PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowRunID: ${{ inputs.WorkflowRunID }}
4044
run: |
4145
# Download-CIArtifact
42-
${{ github.action_path }}\scripts\main.ps1
46+
${{ github.action_path }}/scripts/main.ps1
4347
4448
- name: Download Artifact
4549
uses: actions/download-artifact@v4
4650
with:
4751
name: ${{ inputs.ArtifactName }}
48-
path: ${{ inputs.WorkingDirectory }}
52+
path: ${{ steps.workflow_run_id.outputs.Path }}
4953
github-token: ${{ github.token }}
5054
run-id: ${{ steps.workflow_run_id.outputs.RunID }}

scripts/main.ps1

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
[CmdletBinding(DefaultParameterSetName = 'WorkflowID')]
2-
param(
3-
# The ID of the workflow to get the run for.
4-
[Parameter()]
5-
[string] $WorkflowID = $env:GITHUB_ACTION_INPUT_WorkflowID,
6-
7-
# The ID of the workflow run to verify.
8-
[Parameter()]
9-
[string] $WorkflowRunID = $env:GITHUB_ACTION_INPUT_WorkflowRunID
10-
)
11-
12-
if ($WorkflowRunID) {
13-
Write-Output '::group::Verify Workflow Run'
14-
gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' "/repos/$env:GITHUB_REPOSITORY/actions/runs/$WorkflowRunID"
15-
Write-Output '::endgroup::'
16-
} else {
17-
Write-Output '::group::Get PR'
18-
$PR = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
19-
"/repos/$env:GITHUB_REPOSITORY/commits/$env:GITHUB_SHA/pulls" | ConvertFrom-Json
20-
$PR | ConvertTo-Json -Depth 100
21-
if ($PR.Count -ne 1) {
22-
throw "Expected 1 PR, but found [$($PR.Count)]."
23-
}
24-
Write-Output '::endgroup::'
25-
26-
Write-Output '::group::Get WorkflowRun'
27-
$WorkflowRuns = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
28-
"/repos/$env:GITHUB_REPOSITORY/actions/workflows/$WorkflowID/runs?head_sha=$($PR.head.sha)" |
29-
ConvertFrom-Json | Select-Object -ExpandProperty workflow_runs
30-
$WorkflowRuns | ConvertTo-Json -Depth 100
31-
$WorkflowRunID = $WorkflowRuns.id
32-
Write-Output '::endgroup::'
33-
}
34-
35-
Write-Output "Workflow Run ID: [$WorkflowRunID]"
36-
"RunID=$WorkflowRunID" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
1+
[CmdletBinding(DefaultParameterSetName = 'WorkflowID')]
2+
param(
3+
# The ID of the workflow to get the run for.
4+
[Parameter()]
5+
[string] $WorkflowID = $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowID,
6+
7+
# The ID of the workflow run to verify.
8+
[Parameter()]
9+
[string] $WorkflowRunID = $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowRunID
10+
)
11+
12+
if ($WorkflowRunID) {
13+
Write-Output '::group::Verify Workflow Run'
14+
gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' "/repos/$env:GITHUB_REPOSITORY/actions/runs/$WorkflowRunID"
15+
Write-Output '::endgroup::'
16+
} else {
17+
Write-Output '::group::Get PR'
18+
$PR = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
19+
"/repos/$env:GITHUB_REPOSITORY/commits/$env:GITHUB_SHA/pulls" | ConvertFrom-Json
20+
$PR | ConvertTo-Json -Depth 100
21+
if ($PR.Count -ne 1) {
22+
throw "Expected 1 PR, but found [$($PR.Count)]."
23+
}
24+
Write-Output '::endgroup::'
25+
26+
Write-Output '::group::Get WorkflowRun'
27+
$WorkflowRuns = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
28+
"/repos/$env:GITHUB_REPOSITORY/actions/workflows/$WorkflowID/runs?head_sha=$($PR.head.sha)" |
29+
ConvertFrom-Json | Select-Object -ExpandProperty workflow_runs
30+
$WorkflowRuns | ConvertTo-Json -Depth 100
31+
$WorkflowRunID = $WorkflowRuns.id
32+
Write-Output '::endgroup::'
33+
}
34+
35+
Write-Output "Workflow Run ID: [$WorkflowRunID]"
36+
"RunID=$WorkflowRunID" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
37+
38+
$path = [string]::IsNullOrEmpty($env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_Path) ? '.' : $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_Path
39+
$path = Resolve-Path -Path $path | Select-Object -ExpandProperty Path
40+
41+
"Path=$path" | Out-File -FilePath $env:GITHUB_OUTPUT -Append

0 commit comments

Comments
 (0)