Skip to content

Initial general CI workflows #34

Initial general CI workflows

Initial general CI workflows #34

name: Handle deployment commands in PR Comments
on:
issue_comment:
types:
- created
jobs:
handle-deployment-on-pr-comment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Parse Deployment Command
uses: actions/github-script@v7
id: parse_command
with:
script: |
const { default: parseDeployCommand } =
await import('${{ github.workspace }}/actions_scripts/parse_deployment_command.js');
parseDeployCommand({context, core});
- name: Get GH Zero Day Code APP token
if: ${{ !github.event.act }}
uses: actions/create-github-app-token@v1
id: zdc-auth-app-token
with:
app-id: ${{ vars.ZDC_AUTH_APP_ID }}
private-key: ${{ secrets.ZDC_AUTH_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Notify the user
uses: actions/github-script@v7
id: notify_user
with:
script: |
const environment = `${{ steps.parse_command.outputs.environment }}`;
const project = `${{ steps.parse_command.outputs.project }}`;
const infra = `${{ steps.parse_command.outputs.infra }}`;
const { default: notifyUser } =
await import('${{ github.workspace }}/actions_scripts/notify_user.js');
return await notifyUser({github, context, environment, project, infra});
- name: Trigger Deployment Workflow
uses: actions/github-script@v7
id: trigger_deployment_workflow
with:
github-token: ${{ steps.zdc-auth-app-token.outputs.token || github.token }}
script: |
const environment = `${{ steps.parse_command.outputs.environment }}`;
const project = `${{ steps.parse_command.outputs.project }}`;
const workflowId = `deploy-${environment}.yml`;
let result = "";
let details = "";
try {
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: project,
workflow_id: workflowId,
ref: 'main', // TODO: Change branch to ref if pre, otherwise PRO should be only on main
});
status = 'OK';
details = 'succedeed';
} catch (ex) {
console.log(`FAILED TO TRIGGER WORKFLOW:\n${ex}`);
status = 'ERR';
details = `Failed to trigger the workflow ${workflowId} on repo: ${project}`;
}
// Return triggered details
return {
workflowId: workflowId,
status: status,
details: details,
};
- name: Deploy Infra
if: steps.parse_command.outputs.infra != ''
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
case "${{ steps.parse_command.outputs.infra }}" in
postgres)
echo "Deploying Postgres..."
docker run -d --name postgres --restart always -e POSTGRES_PASSWORD=mysecretpassword postgres
;;
redis)
echo "Deploying Redis..."
docker run -d --name redis --restart always redis
;;
all)
echo "Deploying Postgres and Redis..."
docker run -d --name postgres --restart always -e POSTGRES_PASSWORD=mysecretpassword postgres
docker run -d --name redis --restart always redis
;;
*)
echo "Unknown infra: ${{ steps.parse_command.outputs.infra }}"
;;
esac
- name: Update Deployment Status
uses: actions/github-script@v7
id: update-comment-with-deployment-status
with:
script: |
const steps = ${{ toJSON(steps) }};
const { default: updatePrComment } =
await import('${{ github.workspace }}/actions_scripts/update_pr_comment.js');
await updatePrComment(github, context, steps);