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
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ The following re-usable workflows are available:

The following re-usable actions are available:

| Name | Filename | Description | Inputs | Outputs |
|-------------------|-----------------------------------------|------------------------------|-------------------------------------------------|---------|
| Docker Build | `actions/docker-build/action.yaml` | Docker Login, Build and Push | See [Docker Build Action](#docker-build-action) | - |
| Build Helm Charts | `actions/build-helm-charts/action.yaml` | Lints and builds Helm chart | See [Build Helm Charts](#build-helm-charts) | - |
| Name | Filename | Description | Inputs | Outputs |
|----------------------------|-------------------------------------------|------------------------------------------------|--------------------------------------------------------|---------|
| Docker Build | `actions/docker-build/action.yaml` | Docker Login, Build and Push | See [Docker Build Action](#docker-build-action) | - |
| Build Helm Charts | `actions/build-helm-charts/action.yaml` | Lints and builds Helm chart | See [Build Helm Charts](#build-helm-charts) | - |
| Get last successful run ID | `actions/last-successful-run/action.yaml` | Fetches the run ID of the last successful run | See [Get last successful run ID](#last-successful-run) | RUN_ID |

### Docker Build Action

Expand Down Expand Up @@ -81,4 +82,24 @@ The following re-usable actions are available:
VERSION: ${{ env.VERSION }}
APP_VERSION: ${{ env.VERSION }}.${{ env.DATETIME }}
CHART_NAME: ${{ env.IMAGE }}
```


### Get last successful run ID

**Inputs**:
* `branch`: The branch that should be checked. default: `main`
* `workflow-file`: The workflow that should be checked. default: `CI.yaml`
* `include-bot-runs`: Wether or not, workflow runs from bot accounts should be considered too. default: `true`

**Example Usage**:

```yaml
- name: Get run id
id: get_run_id
uses: keptn/gh-automation/.github/actions/last-successful-run@v1.7
with:
branch: "main"
workflow-file: "CI.yaml"
include-bot-runs: "true"
```
38 changes: 38 additions & 0 deletions last-successful-run/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Get last successful run id"
description: "Get the ID of the last successful run of a given branch"
inputs:
branch:
required: false
description: "The branch that should be checked"
default: "main"
workflow-file:
required: false
description: "The workflow that should be checked"
default: "CI.yaml"
include-bot-runs:
required: false
description: "Set to true/false wether or not Bot runs should be checked too"
default: "true"

runs:
using: composite
steps:
- name: Find latest successful run ID
id: last_run_id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INCLUDE_BOT: ${{ inputs.include-bot-runs }}
run: |
if [[ "$INCLUDE_BOT" = "true" ]]; then
INCLUDE_BOT_CHECK = 'and (.head_commit.author.name | endswith("[bot]") | not )'
fi
RUN_ID=$(\
curl -sL \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token $GITHUB_TOKEN" \
"api.github.com/repos/${{ github.repository }}/actions/workflows/${{ inputs.workflow-file }}/runs?branch=${{ inputs.branch }}" | \
jq '[.workflow_runs[] | select(
(.head_commit != null) $INCLUDE_BOT_CHECK and ( .conclusion == "success" )
)][0] | .id')
echo "Run ID that will be used to download artifacts from: $RUN_ID"
echo "RUN_ID=$RUN_ID" >> $GITHUB_OUTPUT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] missing newline