Skip to content

updated workflow_id

updated workflow_id #9

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
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.PERSONAL_ACCESS_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: context.payload.workflow_run.workflow_id,
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;
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- 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: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy-key.pem
chmod 600 ~/.ssh/deploy-key.pem
cat >> ~/.ssh/config <<END
Host my-vps
HostName $SSH_IP
User $SSH_USER
IdentityFile ~/.ssh/deploy-key.pem
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_IP: ${{ secrets.SSH_IP }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- 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"