Skip to content

Commit

Permalink
Add download artifacts action
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnr committed Mar 12, 2024
1 parent b2277b7 commit 0b1764b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/actions/get-workflow-run-id/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Get Workflow Run ID

Get the ID of the latest successful workflow run.

Accepts the following inputs:

* `repository` (Required) - The repository owner and name (e.g. `spring-projects/spring-security`).
* `workflow-id` (Required) - The ID of the workflow or the workflow file name.

Produces the following output:

* `run-id` - The ID of the latest successful workflow run.

## Installation

```yaml
- id: get-workflow-run-id
name: Get Workflow Run ID
uses: spring-io/spring-security-release-tools/.github/actions/get-workflow-run-id@v1
with:
repository: owner/repo
workflow-id: build-and-deploy.yml
```
## Example Usage
```yaml
name: Download Artifacts

on: push

permissions:
actions: read

jobs:
download-artifacts:
name: Download Artifacts
runs-on: ubuntu-latest
steps:
- id: get-workflow-run-id
name: Get Workflow Run ID
uses: spring-io/spring-security-release-tools/.github/actions/get-workflow-run-id@v1
with:
repository: spring-projects/spring-security
workflow-id: continuous-integration-workflow.yml
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: maven-repository
path: build
repository: spring-projects/spring-security
github-token: ${{ github.token }}
run-id: ${{ steps.get-workflow-run-id.outputs.run-id }}
- name: Unzip Artifacts
run: pushd build && unzip maven-repository.zip && popd
```
28 changes: 28 additions & 0 deletions .github/actions/get-workflow-run-id/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'Get Workflow Run ID'
description: 'Get the ID of the latest successful workflow run for a given workflow.'
author: 'sjohnr'

inputs:
repository:
description: 'The repository owner and name (e.g. spring-projects/spring-security).'
required: true
workflow-id:
description: 'The ID of the workflow or the workflow file name (e.g. build-and-deploy.yml).'
required: true

outputs:
run-id:
description: 'The ID of the latest successful workflow run.'
value: ${{ steps.get-workflow-run-id.outputs.run-id }}

runs:
using: 'composite'
steps:
- id: get-workflow-run-id
name: Get Workflow Run ID
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
runId=$(gh run list -R ${{ inputs.repository }} -w ${{ inputs.workflow-id }} -s success --json databaseId -q '.[0].databaseId')
echo "run-id=$runId" >> $GITHUB_OUTPUT

0 comments on commit 0b1764b

Please sign in to comment.