Skip to content

Commit cc27caa

Browse files
committed
ci: update workflows
1 parent b981441 commit cc27caa

2 files changed

Lines changed: 39 additions & 71 deletions

File tree

.github/workflows/promote.yml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,13 @@ jobs:
1919
2020
echo "ref=$(echo "$DEPLOYMENT_JSON" | jq -r '.ref')" >> "$GITHUB_OUTPUT"
2121
echo "sha=$(echo "$DEPLOYMENT_JSON" | jq -r '.sha')" >> "$GITHUB_OUTPUT"
22-
23-
- name: Create production deployment
24-
id: prod_deploy
25-
run: |
26-
jq -n \
27-
--arg ref "${{ steps.staging.outputs.ref }}" \
28-
--arg sha "${{ steps.staging.outputs.sha }}" \
29-
--arg environment "production" \
30-
'{ref: $ref, sha: $sha, environment: $environment, auto_merge: false, required_contexts: []}' \
31-
> payload.json
32-
33-
DEPLOY_ID=$(gh api \
34-
-X POST \
35-
-H "Accept: application/vnd.github+json" \
36-
repos/${{ github.repository }}/deployments \
37-
--input payload.json \
38-
--jq '.id')
39-
40-
echo "id=$DEPLOY_ID" >> "$GITHUB_OUTPUT"
22+
23+
- uses: ilyvion-contrib/ci-utils/create-deployment@main
24+
id: deployment
25+
with:
26+
ref: ${{ steps.staging.outputs.ref }}
27+
sha: ${{ steps.staging.outputs.sha }}
28+
environment: "production"
4129

4230
- uses: ilyvion-contrib/ci-utils/setup-ssh@main
4331
with:
@@ -58,7 +46,7 @@ jobs:
5846
gh api \
5947
-X POST \
6048
-H "Accept: application/vnd.github+json" \
61-
repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \
49+
repos/${{ github.repository }}/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses \
6250
-f state="success"
6351
6452
- name: Mark deployment as failure
@@ -67,5 +55,5 @@ jobs:
6755
gh api \
6856
-X POST \
6957
-H "Accept: application/vnd.github+json" \
70-
repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \
58+
repos/${{ github.repository }}/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses \
7159
-f state="failure"

.github/workflows/workflow.yml

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010

11-
- uses: ilyvion-contrib/container-ci-build@main
11+
- uses: ilyvion-contrib/ci-utils/container-build@main
1212
with:
1313
image: questionablextensions
1414

@@ -22,70 +22,50 @@ jobs:
2222
deploy:
2323
runs-on: ubuntu-latest
2424
needs: build
25-
outputs:
26-
deployment_id: ${{ steps.create_deployment.outputs.deployment_id }}
25+
env:
26+
GH_TOKEN: ${{ github.token }}
2727
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
2828
steps:
29-
- name: Create Deployment
30-
id: create_deployment
31-
run: |
32-
deployment_response=$(curl -fsS -X POST \
33-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
34-
-H "Accept: application/vnd.github+json" \
35-
https://api.github.com/repos/${{ github.repository }}/deployments \
36-
-d '{
37-
"ref": "${{ github.sha }}",
38-
"environment": "staging",
39-
"auto_merge": false,
40-
"required_contexts": [],
41-
"description": "Deploying to staging"
42-
}')
43-
deployment_id=$(echo "$deployment_response" | jq -r '.id')
44-
echo "deployment_id=$deployment_id" >> "$GITHUB_OUTPUT"
45-
46-
curl -fsS -X POST \
47-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
48-
-H "Accept: application/vnd.github+json" \
49-
https://api.github.com/repos/${{ github.repository }}/deployments/${deployment_id}/statuses \
50-
-d '{"state": "in_progress"}'
29+
- uses: ilyvion-contrib/ci-utils/create-deployment@main
30+
id: deployment
31+
with:
32+
ref: ${{ github.ref }}
33+
sha: ${{ github.sha }}
34+
environment: "staging"
5135

5236
- name: Download artifact
5337
uses: actions/download-artifact@v4
5438
with:
5539
name: questionablextensions-tar
5640

57-
- uses: ilyvion-contrib/container-ci-deploy@main
41+
- uses: ilyvion-contrib/ci-utils/setup-ssh@main
5842
with:
5943
ssh_known_hosts: ${{ secrets.deploy_known_hosts }}
6044
ssh_private_key: ${{ secrets.deploy_key }}
45+
ssh_host: ${{ secrets.deploy_target }}
46+
ssh_port: ${{ secrets.deploy_port }}
47+
48+
- uses: ilyvion-contrib/ci-utils/container-deploy@main
49+
with:
6150
ssh_user: ${{ secrets.deploy_user }}
6251
ssh_host: ${{ secrets.deploy_target }}
6352
ssh_port: ${{ secrets.deploy_port }}
6453
image: questionablextensions
65-
66-
- name: Update Deployment Status
54+
55+
- name: Mark deployment as success
56+
if: success()
6757
run: |
68-
curl -X POST \
69-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
58+
gh api \
59+
-X POST \
7060
-H "Accept: application/vnd.github+json" \
71-
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses \
72-
-d '{
73-
"state": "success",
74-
"description": "Deployment succeeded"
75-
}'
76-
77-
report-failure:
78-
runs-on: ubuntu-latest
79-
needs: deploy
80-
if: failure()
81-
steps:
82-
- name: Report failure to GitHub Deployment
61+
repos/${{ github.repository }}/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses \
62+
-f state="success"
63+
64+
- name: Mark deployment as failure
65+
if: failure()
8366
run: |
84-
curl -sSL -X POST \
85-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
86-
-H "Accept: application/vnd.github+json" \
87-
https://api.github.com/repos/${{ github.repository }}/deployments/${{ needs.deploy.outputs.deployment_id }}/statuses \
88-
-d '{
89-
"state": "failure",
90-
"description": "Deployment failed"
91-
}'
67+
gh api \
68+
-X POST \
69+
-H "Accept: application/vnd.github+json" \
70+
repos/${{ github.repository }}/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses \
71+
-f state="failure"

0 commit comments

Comments
 (0)