-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (49 loc) · 1.93 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Discord Bot Deployment
on:
push:
branches:
- master # Change this to your main branch name
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Kill all running instances
run: |
# Define your GitHub Personal Access Token (PAT) with workflow permissions
GITHUB_TOKEN=${{ secrets.GH_TOKEN }}
# Get the current workflow run ID
WORKFLOW_RUN_ID=$(echo $GITHUB_RUN_ID)
# Get the list of workflow runs for the current workflow
RUNS=$(curl -s -X GET "https://api.github.com/repos/JHVIW/Secret-Santa-Bot/actions/runs" -H "Authorization: token $GITHUB_TOKEN")
# Sort the runs by creation timestamp in descending order
SORTED_RUNS=$(echo "${RUNS}" | jq '[.workflow_runs[]] | sort_by(.created_at) | reverse')
# Loop through the sorted runs and find the last running one to cancel
for row in $(echo "${SORTED_RUNS}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
RUN_ID=$(_jq '.id')
STATUS=$(_jq '.status')
if [ "$STATUS" == "in_progress" ] && [ "$RUN_ID" != "$WORKFLOW_RUN_ID" ]; then
# Cancel the last running workflow and exit the loop
curl -s -X POST "https://api.github.com/repos/${{ github.repository }}/actions/runs/$RUN_ID/cancel" -H "Authorization: token $GITHUB_TOKEN"
break
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install dependencies
run: npm install
- name: Deploy bot
run: |
# Any additional deployment steps you need, e.g., restarting the bot
npm start
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}