Skip to content

Commit 0417952

Browse files
committed
Split ci.yml into build.yml and deploy.yml
1 parent 4a38ba3 commit 0417952

File tree

2 files changed

+88
-86
lines changed

2 files changed

+88
-86
lines changed

Diff for: .github/workflows/build.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: '*'
6+
pull_request:
7+
branches: '*'
8+
workflow_dispatch:
9+
workflow_call:
10+
outputs:
11+
image-tag:
12+
value: ${{ jobs.build-image.outputs.tag }}
13+
14+
env:
15+
NODE_VERSION: 18
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: object-object/discord-github-utils
18+
19+
jobs:
20+
build-image:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
tag: ${{ fromJson(steps.meta.outputs.json).tags[0] }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: docker/setup-buildx-action@v3
27+
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract image metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
41+
- name: Build Docker image
42+
id: build
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: .
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}
48+
outputs: type=docker,dest=/tmp/image.tar
49+
50+
- name: Upload image artifact
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: docker-image
54+
path: /tmp/image.tar
55+
retention-days: 7
56+
57+
build-aws-cdk:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
- uses: eifinger/setup-rye@v4
62+
with:
63+
enable-cache: true
64+
github-token: ${{ secrets.GITHUB_TOKEN }}
65+
- uses: object-Object/ci/setup@v0
66+
with:
67+
node-version: ${{ env.NODE_VERSION }}
68+
npm-packages: aws-cdk
69+
70+
- name: Sync dependencies
71+
run: rye sync --no-lock --no-dev
72+
73+
- name: Synth aws-cdk stack
74+
run: cdk synth --ci --no-lookups --strict
75+
76+
- name: Upload synth artifact
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: aws-cdk-synth
80+
path: cdk.out

Diff for: .github/workflows/ci.yml renamed to .github/workflows/deploy.yml

+8-86
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,30 @@
1-
name: Build and deploy
1+
name: Deploy
22

33
on:
44
push:
5-
branches: '*'
65
tags: 'v[0-9]+.[0-9]+.[0-9]+*'
7-
pull_request:
8-
branches: '*'
96
workflow_dispatch:
10-
inputs:
11-
deploy:
12-
type: boolean
13-
default: false
147

158
env:
169
NODE_VERSION: 18
1710
REGISTRY: ghcr.io
1811
IMAGE_NAME: object-object/discord-github-utils
1912

2013
jobs:
21-
build-image:
22-
runs-on: ubuntu-latest
23-
outputs:
24-
tag: ${{ fromJson(steps.meta.outputs.json).tags[0] }}
25-
steps:
26-
- uses: actions/checkout@v4
27-
- uses: docker/setup-buildx-action@v3
28-
29-
- name: Login to GitHub Container Registry
30-
uses: docker/login-action@v3
31-
with:
32-
registry: ${{ env.REGISTRY }}
33-
username: ${{ github.actor }}
34-
password: ${{ secrets.GITHUB_TOKEN }}
35-
36-
- name: Extract image metadata
37-
id: meta
38-
uses: docker/metadata-action@v5
39-
with:
40-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41-
42-
- name: Build Docker image
43-
id: build
44-
uses: docker/build-push-action@v5
45-
with:
46-
context: .
47-
tags: ${{ steps.meta.outputs.tags }}
48-
labels: ${{ steps.meta.outputs.labels }}
49-
outputs: type=docker,dest=/tmp/image.tar
50-
51-
- name: Upload image artifact
52-
uses: actions/upload-artifact@v4
53-
with:
54-
name: docker-image
55-
path: /tmp/image.tar
56-
retention-days: 7
57-
58-
build-aws-cdk:
59-
runs-on: ubuntu-latest
60-
steps:
61-
- uses: actions/checkout@v4
62-
- uses: eifinger/setup-rye@v4
63-
with:
64-
enable-cache: true
65-
github-token: ${{ secrets.GITHUB_TOKEN }}
66-
- uses: object-Object/ci/setup@v0
67-
with:
68-
node-version: ${{ env.NODE_VERSION }}
69-
npm-packages: aws-cdk
70-
71-
- name: Sync dependencies
72-
run: rye sync --no-lock --no-dev
73-
74-
- name: Synth aws-cdk stack
75-
run: cdk synth --ci --no-lookups --strict
76-
77-
- name: Upload synth artifact
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: aws-cdk-synth
81-
path: cdk.out
82-
83-
# dummy "gate" job to restrict when the deployment jobs can run
84-
setup-deployments:
85-
needs:
86-
- build-image
87-
- build-aws-cdk
88-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') || inputs.deploy
89-
runs-on: ubuntu-latest
90-
steps:
91-
- run: echo
14+
build:
15+
uses: ./.github/workflows/build.yml
16+
secrets: inherit
9217

9318
push-image:
9419
needs:
95-
- setup-deployments
96-
- build-image
20+
- build
9721
runs-on: ubuntu-latest
9822
permissions:
9923
contents: read
10024
packages: write
10125
environment:
10226
name: docker
103-
url: https://${{ needs.build-image.outputs.tag }}
27+
url: https://${{ needs.build.outputs.image-tag }}
10428
outputs:
10529
digest: ${{ steps.digest.outputs.value }}
10630
steps:
@@ -127,12 +51,11 @@ jobs:
12751

12852
- name: Get image digest
12953
id: digest
130-
run: echo "value=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ needs.build-image.outputs.tag }})" >> "$GITHUB_OUTPUT"
54+
run: echo "value=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ needs.build.outputs.image-tag }})" >> "$GITHUB_OUTPUT"
13155

13256
deploy-aws-cdk:
13357
needs:
134-
- setup-deployments
135-
- build-aws-cdk
58+
- build
13659
runs-on: ubuntu-latest
13760
permissions:
13861
contents: read
@@ -164,7 +87,6 @@ jobs:
16487

16588
deploy-codedeploy:
16689
needs:
167-
- setup-deployments
16890
- push-image
16991
- deploy-aws-cdk
17092
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)