Skip to content

Commit

Permalink
made tests depend on deploy and checking conditions to send discord n…
Browse files Browse the repository at this point in the history
…otifs
  • Loading branch information
gigabite-pro committed Aug 9, 2024
1 parent f8dc703 commit 99499c0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,43 @@ on:
workflow_dispatch:

jobs:
trigger-tests:
name: "Trigger the Test Workflow"
runs-on: ubuntu-latest
steps:
- name: Trigger Test Workflow
id: trigger_tests
uses: benc-uk/workflow-dispatch@v1
with:
workflow: "test.yml"
token: ${{ secrets.GITHUB_TOKEN }}
ref: "main"
- name: Wait for Test Workflow to Complete
uses: actions/github-script@v6
id: check_run
with:
script: |
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'test.yml',
branch: 'main',
status: 'completed'
});
const run = runs.workflow_runs.find(run => run.conclusion === 'success');
if (!run) {
throw new Error("Test workflow failed or not completed.");
}
return run.id;
- name: Continue if Tests Passed
if: ${{ steps.check_run.outputs.result == 'success' }}
run: echo "Tests passed, continuing with deployment."
deploy:
name: "Deploy to VPS"
runs-on: ubuntu-latest
needs: trigger-tests
if: ${{ needs.trigger-tests.outputs.check_run.result == 'success' }}
steps:
- name: Configure SSH
run: |
Expand All @@ -30,3 +64,18 @@ jobs:

- name: Deploy site
run: ssh my-vps '~/redeploy-site.sh'

- name: Print Container Status
run: ssh my-vps 'docker-compose ps'

- name: Send Discord Notification
run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=🚀 Deployment Successful"

failure-notification:
name: "Notify Failure"
runs-on: ubuntu-latest
needs: deploy
if: ${{ failure() }}
steps:
- name: Send Discord Notification on Failure
run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=🚨 Deployment Failed"

0 comments on commit 99499c0

Please sign in to comment.