Skip to content

Updated readme.md

Updated readme.md #51

Workflow file for this run

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 }}