mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-21 07:46:04 +08:00
bb82f5ccb9
* remove server info discord message * delete droplets 5 hours after failure * run_attempt vice run_number
78 lines
3.1 KiB
YAML
78 lines
3.1 KiB
YAML
name: Delete Droplets
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: [Deploy and Test Branch]
|
|
types:
|
|
- completed
|
|
|
|
jobs:
|
|
on-success:
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
steps:
|
|
- name: get logs
|
|
uses: dawidd6/action-download-artifact@v2
|
|
with:
|
|
run_id: ${{ github.event.workflow_run.id}}
|
|
if_no_artifact_found: warn
|
|
- name: discord success message
|
|
uses: appleboy/discord-action@master
|
|
with:
|
|
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
|
|
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
|
|
color: "#42f545"
|
|
username: "GitHub Bot"
|
|
message: "${{ github.repository }}: ${{ github.event.workflow_run.name }} was successful: droplets from this workflow (tag ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}) will be deleted in 15 min"
|
|
file: ./results/results.log
|
|
- name: delete droplets
|
|
if: success() || failure()
|
|
run: |
|
|
sleep 15m
|
|
curl -X GET \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
|
"https://api.digitalocean.com/v2/droplets?tag_name=$TAG"
|
|
env:
|
|
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
|
|
TAG: ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
|
|
|
|
on-failure:
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
|
steps:
|
|
- name: get logs
|
|
uses: dawidd6/action-download-artifact@v2
|
|
with:
|
|
run_id: ${{ github.event.workflow_run.id}}
|
|
if_no_artifact_found: warn
|
|
- name: discord failure message
|
|
uses: appleboy/discord-action@master
|
|
with:
|
|
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
|
|
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
|
|
color: "#990000"
|
|
username: "GitHub Bot"
|
|
message: "${{ github.repository }}: ${{ github.event.workflow_run.name }} failed: droplets from this workflow (tag ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt}}) will be deleted in 5 hours"
|
|
file: ./results/results.log
|
|
- name: discord error message
|
|
uses: appleboy/discord-action@master
|
|
with:
|
|
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
|
|
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
|
|
color: "#990000"
|
|
username: "GitHub Bot"
|
|
message: "errors from ${{ github.event.workflow_run.name }}"
|
|
file: ./results/errors.log
|
|
- name: delete droplets
|
|
if: success() || failure()
|
|
run: |
|
|
sleep 5h
|
|
curl -X GET \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
|
"https://api.digitalocean.com/v2/droplets?tag_name=$TAG"
|
|
env:
|
|
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
|
|
TAG: ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
|