-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from fujiwara/actions
Add Actions to create a issue on GitHub
- Loading branch information
Showing
4 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: "Check RI Expiration" | ||
description: "Check if any Reserved Instances are expiring within a given number of days and create an issue if necessary" | ||
inputs: | ||
days_left: | ||
description: "Number of days left before the RI expires" | ||
required: true | ||
default: "30" | ||
dummy_end_time: | ||
description: "Dummy end time for testing" | ||
required: false | ||
version: | ||
description: "Version of riex to use" | ||
required: true | ||
default: "0.0.5" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Download riex | ||
run: | | ||
curl -sL https://github.com/fujiwara/riex/releases/download/v${{ inputs.version }}/riex_${{ inputs.version }}_linux_amd64.tar.gz -o riex.tar.gz | ||
tar -xzf riex.tar.gz | ||
install -m 755 riex /usr/local/bin | ||
shell: bash | ||
working-directory: /tmp | ||
|
||
- name: Check RI expiration and create an issue if necessary | ||
run: | | ||
days_left=${{ inputs.days_left }} | ||
if [[ "${{ inputs.dummy_end_time }}" != "" ]]; then | ||
opts="--dummy-output --dummy-end-time ${{ inputs.dummy_end_time }}" | ||
fi | ||
output=$(riex $days_left --format markdown $opts) | ||
if [ -z "$output" ]; then | ||
echo "No expiring RIs found." | ||
exit 0 | ||
fi | ||
issue_title="RI Expiring in $days_left Days" | ||
issue_body="The following Reserved Instances are expiring within $days_left days:\n\n$output" | ||
# Check if an issue with the same title already exists | ||
existing_issue=$(gh issue list --search "$issue_title" --state open --json 'number,body' -q '.[] | .number') | ||
if [ -z "$existing_issue" ]; then | ||
# Check if there's a closed issue with the same title | ||
last_closed_issue=$(gh issue list --search "$issue_title" --state closed --json 'number,body' -q 'first(1) | .[] | .number') | ||
if [ -z "$last_closed_issue" ]; then | ||
# Create a new issue only if no open issue exists and there is no closed issue with the same title | ||
gh issue create --title "$issue_title" --body "$issue_body" | ||
else | ||
echo "A closed issue with the same title already exists: Issue #$last_closed_issue" | ||
fi | ||
else | ||
echo "An open issue with the same title already exists: Issue #$existing_issue" | ||
fi | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters