2023-03-30 01:56:34 +08:00
|
|
|
name: Delete Droplets
|
|
|
|
|
|
|
|
on:
|
2023-03-30 02:11:11 +08:00
|
|
|
workflow_run:
|
2023-03-30 02:21:39 +08:00
|
|
|
workflows: [Deploy and Test Branch]
|
2023-03-30 01:56:34 +08:00
|
|
|
types:
|
|
|
|
- completed
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
on-success:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
|
|
steps:
|
2023-04-21 20:59:15 +08:00
|
|
|
- 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.event.workflow_run.name }} was successful"
|
|
|
|
file: ./results/results.log
|
|
|
|
- name: discord server 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: "droplets from this workflow will be deleted in 15 min"
|
|
|
|
file: ./server/serverinfo.txt
|
2023-03-30 01:56:34 +08:00
|
|
|
- name: delete droplets
|
2023-04-26 02:57:16 +08:00
|
|
|
if: success() || failure()
|
2023-03-30 01:56:34 +08:00
|
|
|
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 }}
|
2023-04-19 23:21:35 +08:00
|
|
|
TAG: ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
|
2023-03-30 01:56:34 +08:00
|
|
|
|
|
|
|
on-failure:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
|
|
|
steps:
|
2023-04-21 20:59:15 +08:00
|
|
|
- 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: "#42f545"
|
|
|
|
username: "GitHub Bot"
|
|
|
|
message: " ${{ github.event.workflow_run.name }} failed"
|
|
|
|
file: ./results/results.log
|
|
|
|
- name: discord server 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: "droplets from this workflow will be deleted in 6 hours"
|
|
|
|
file: ./server/serverinfo.txt
|
|
|
|
- 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
|
2023-03-30 01:56:34 +08:00
|
|
|
- name: delete droplets
|
2023-04-26 02:57:16 +08:00
|
|
|
if: success() || failure()
|
2023-03-30 01:56:34 +08:00
|
|
|
run: |
|
|
|
|
sleep 6h
|
|
|
|
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 }}
|
2023-04-19 23:21:35 +08:00
|
|
|
TAG: ${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
|