GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(gh-actions): :recycle: Break actions in smaller ones. · zerodaycode/app-summoners-sync@5e5720d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • deploy-chatbot.yml
    • deploy-infra.yml
    • deploy-project.yml
    • generate-token.yml
    • notify-user.yml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/deploy-chatbot.yml‎

Copy file name to clipboard
+34-112Lines changed: 34 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,56 @@
1-
name: Handle deployment commands in PR Comments
1+
name: Deploy Chatbot
22

33
on:
44
issue_comment:
55
types:
66
- created
77

88
jobs:
9-
handle-deployment-on-pr-comment:
9+
parse-command:
1010
runs-on: ubuntu-latest
1111
outputs:
12-
artifact: ${{ steps.parse_command.outputs.infra }}
13-
environment: ${{ steps.parse_command.outputs.environment }}
14-
secret_name: ${{ steps.deploy-infra.outputs.secret_name}}
12+
environment: ${{ steps.parse-command.outputs.environment }}
13+
infra: ${{ steps.parse-command.outputs.infra }}
14+
project: ${{ steps.parse-command.outputs.project }}
1515

16-
steps:
17-
- uses: actions/checkout@v4
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
1819

1920
- name: Parse Deployment Command
2021
uses: actions/github-script@v7
21-
id: parse_command
22+
id: parse-command
2223
with:
2324
script: |
2425
const { default: parseDeployCommand } =
25-
await import('${{ github.workspace }}/actions_scripts/parse_deployment_command.js');
26-
27-
parseDeployCommand({context, core});
28-
29-
- name: Get GH Zero Day Code APP token
30-
if: ${{ !github.event.act }}
31-
uses: actions/create-github-app-token@v1
32-
id: zdc-auth-app-token
33-
with:
34-
app-id: ${{ vars.ZDC_AUTH_APP_ID }}
35-
private-key: ${{ secrets.ZDC_AUTH_PRIVATE_KEY }}
36-
owner: ${{ github.repository_owner }}
37-
38-
- name: Notify the user
39-
uses: actions/github-script@v7
40-
id: notify_user
41-
with:
42-
script: |
43-
const environment = `${{ steps.parse_command.outputs.environment }}`;
44-
const project = `${{ steps.parse_command.outputs.project }}`;
45-
const infra = `${{ steps.parse_command.outputs.infra }}`;
46-
47-
const { default: notifyUser } =
48-
await import('${{ github.workspace }}/actions_scripts/notify_user.js');
49-
50-
return await notifyUser({github, context, core, environment, project, infra});
51-
52-
- name: Trigger Deployment Workflow
53-
uses: actions/github-script@v7
54-
id: trigger_deployment_workflow
55-
with:
56-
github-token: ${{ steps.zdc-auth-app-token.outputs.token || github.token }}
57-
script: |
58-
const environment = `${{ steps.parse_command.outputs.environment }}`;
59-
const project = `${{ steps.parse_command.outputs.project }}`;
60-
const workflowId = `deploy-${environment}.yml`;
61-
62-
let result = "";
63-
let details = "";
26+
await import(`${{ github.workspace }}/actions_scripts/parse_deployment_command.js`);
6427
65-
try {
66-
await github.rest.actions.createWorkflowDispatch({
67-
owner: context.repo.owner,
68-
repo: project,
69-
workflow_id: workflowId,
70-
ref: 'main', // TODO: Change branch to ref if pre, otherwise PRO should be only on main
71-
});
72-
status = 'OK';
73-
details = 'succedeed';
74-
} catch (ex) {
75-
console.log(`FAILED TO TRIGGER WORKFLOW:\n${ex}`);
76-
status = 'ERR';
77-
details = `Failed to trigger the workflow ${workflowId} on repo: ${project}`;
78-
}
28+
parseDeployCommand({ context, core });
7929
80-
// Return triggered details
81-
return {
82-
workflowId: workflowId,
83-
status: status,
84-
details: details,
85-
};
30+
generate-token:
31+
needs: parse-command
32+
uses: zerodaycode/app-summoners-sync/.github/workflows/generate-token.yml@develop
8633

87-
88-
- name: Deploy Infra
89-
id: deploy-infra
90-
if: steps.parse_command.outputs.infra != ''
91-
run: |
92-
case "${{ steps.parse_command.outputs.infra }}" in
93-
postgres)
94-
echo "Deploying Postgres..."
95-
;;
96-
redis)
97-
echo "Deploying Redis..."
98-
;;
99-
*)
100-
echo "Unknown infra: ${{ steps.parse_command.outputs.infra }}"
101-
exit 1
102-
;;
103-
esac
104-
INFRA_UPPER=$(echo "${{steps.parse_command.outputs.infra }}" | tr 'a-z' 'A-Z')
105-
ENV_UPPER=$(echo "${{ steps.parse_command.outputs.environment }}" | tr 'a-z' 'A-Z')
106-
107-
secret_name="SS_${INFRA_UPPER}_${ENV_UPPER}"
108-
109-
echo "Generated secret_name: $secret_name"
110-
echo "SECRET_NAME=$secret_name" >> $GITHUB_OUTPUT
111-
112-
113-
- name: Update Deployment Status
114-
if: steps.parse_command.outputs.project != '' # TODO provisional ñapa while we don't add the remaining outputs
115-
uses: actions/github-script@v7
116-
id: update-comment-with-deployment-status
117-
with:
118-
script: |
119-
const steps = ${{ toJSON(steps) }};
120-
121-
const { default: updatePrComment } =
122-
await import('${{ github.workspace }}/actions_scripts/update_pr_comment.js');
123-
124-
await updatePrComment(github, context, steps);
34+
notify-user:
35+
needs: generate-token
36+
uses: zerodaycode/app-summoners-sync/.github/workflows/notify-user.yml@develop
37+
with:
38+
environment: ${{ needs.parse-command.outputs.environment }}
39+
project: ${{ needs.parse-command.outputs.project }}
40+
infra: ${{ needs.parse-command.outputs.infra }}
41+
42+
trigger-deployment:
43+
needs: notify-user
44+
if: needs.parse-command.outputs.project != ''
45+
uses: zerodaycode/app-summoners-sync/.github/workflows/trigger-deployment.yml@develop
46+
with:
47+
project: ${{ needs.parse-command.outputs.project }}
48+
environment: ${{ needs.parse-command.outputs.environment }}
12549

126-
call-deploy-infra-artifact:
127-
needs: handle-deployment-on-pr-comment
50+
deploy-infra:
51+
needs: notify-user
52+
if: needs.parse-command.outputs.infra != ''
12853
uses: zerodaycode/app-summoners-sync/.github/workflows/deploy-infra.yml@develop
12954
with:
130-
artifact: ${{ needs.handle-deployment-on-pr-comment.outputs.artifact }}
131-
environment: ${{ needs.handle-deployment-on-pr-comment.outputs.environment }}
132-
secret_name: ${{ needs.handle-deployment-on-pr-comment.outputs.secret_name }}
133-
secrets: inherit
134-
55+
artifact: ${{ needs.parse-command.outputs.infra }}
56+
environment: ${{ needs.parse-command.outputs.environment }}
Collapse file

‎.github/workflows/deploy-infra.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/deploy-infra.yml
+22-4Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ on:
77
environment:
88
required: true
99
type: string
10-
secret_name:
11-
required: true
12-
type: string
1310
jobs:
1411
deploy_infra_artifact:
1512
runs-on: ubuntu-latest
1613
steps:
14+
- name: Validate Artifact
15+
id: validate-artifact
16+
run: |
17+
case "${{ inputs.artifact }}" in
18+
postgres|redis)
19+
echo "Valid artifact: ${{ inputs.artifact }}" ;;
20+
*)
21+
echo "Unknown infra: ${{ inputs.artifact }}"
22+
exit 1 ;;
23+
esac
1724
- name: Build compose filename
1825
id: build-compose-filename
1926
run: |
@@ -23,6 +30,17 @@ jobs:
2330
echo "Generated filename: $filename"
2431
echo "COMPOSE_FILENAME=$filename" >> $GITHUB_ENV
2532
33+
- name: Deploy Specific Infrastructure
34+
id: generate-secret-name
35+
run: |
36+
INFRA_UPPER=$(echo "${{ inputs.artifact }}" | tr 'a-z' 'A-Z')
37+
ENV_UPPER=$(echo "${{ inputs.environment }}" | tr 'a-z' 'A-Z')
38+
39+
secret_name="SS_${INFRA_UPPER}_${ENV_UPPER}"
40+
41+
echo "Generated secret_name: $secret_name"
42+
echo "SECRET_NAME=$secret_name" >> $GITHUB_OUTPUT
43+
2644
- name: Checkout Code
2745
uses: actions/checkout@v4
2846

@@ -47,6 +65,6 @@ jobs:
4765
script: |
4866
cd /opt/summoners-sync/infra/docker
4967
50-
echo "${{ secrets[inputs.secret_name] }}" > .env
68+
echo "${{secrets[steps.generate-secret.outputs.SECRET_NAME] }}" > .env
5169
ls -l
5270
docker-compose --env-file .env -f ${{ env.COMPOSE_FILENAME }} up -d
Collapse file

‎.github/workflows/deploy-project.yml‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Deploy Project Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
project:
7+
required: true
8+
type: string
9+
environment:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
trigger-deployment:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Trigger Deployment Workflow
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const environment = `"${{ inputs.environment }}"`;
22+
const project = `"${{ inputs.project }}"`;
23+
const workflowId = `deploy-${environment}.yml`;
24+
25+
try {
26+
await github.rest.actions.createWorkflowDispatch({
27+
owner: context.repo.owner,
28+
repo: project,
29+
workflow_id: workflowId,
30+
ref: 'main', // Adjust this if necessary based on branch/ref logic
31+
});
32+
} catch (error) {
33+
core.setFailed(`Failed to trigger the workflow: ${error.message}`);
34+
}
Collapse file

‎.github/workflows/generate-token.yml‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Generate Token
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
generate-token:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
token: ${{ steps.generate-token.outputs.token }}
11+
steps:
12+
- name: Generate GitHub App Token
13+
uses: actions/create-github-app-token@v1
14+
id: generate-token
15+
with:
16+
app-id: ${{ vars.ZDC_AUTH_APP_ID }}
17+
private-key: ${{ secrets.ZDC_AUTH_PRIVATE_KEY }}
18+
owner: ${{ github.repository_owner }}
Collapse file

‎.github/workflows/notify-user.yml‎

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Notify User
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
project:
10+
required: true
11+
type: string
12+
infra:
13+
required: true
14+
type: string
15+
16+
jobs:
17+
notify-user:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Notify User
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const environment = `"${{ inputs.environment }}"`;
25+
const project = `"${{ inputs.project }}"`;
26+
const infra = `"${{ inputs.infra }}"`;
27+
28+
const { default: notifyUser } =
29+
await import(`${{ github.workspace }}/actions_scripts/notify_user.js`);
30+
31+
return await notifyUser({github, context, core, environment, project, infra});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.