Skip to content

Commit 2b51e5c

Browse files
committed
feat(ci): Add GitHub pipeline
1 parent a1184e6 commit 2b51e5c

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- enote
7+
tags:
8+
- '**'
9+
pull_request:
10+
branches:
11+
- '**'
12+
13+
env:
14+
APP: sync-storage
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
20+
prepare:
21+
name: Prepare
22+
runs-on: ubuntu-latest
23+
outputs:
24+
APP_VERSION_TAG: ${{ steps.version.outputs.APP_VERSION_TAG }}
25+
if: github.event_name != 'schedule'
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 200
30+
- name: Set APP_VERSION_TAG
31+
id: version
32+
run: |
33+
git tag --delete "$GITHUB_REF" || true
34+
echo "APP_VERSION_TAG=$(git describe --always --tags HEAD)" >> $GITHUB_OUTPUT
35+
36+
docker-build:
37+
name: Docker Build
38+
runs-on: ubuntu-latest
39+
needs: [prepare]
40+
if: github.ref == 'refs/heads/enote'
41+
steps:
42+
- uses: actions/checkout@v4
43+
- name: Log in to the Container registry
44+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
- id: docker-metadata
50+
uses: docker/metadata-action@v4
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=raw,value=${{ needs.prepare.outputs.APP_VERSION_TAG }}
55+
- name: Build and push Docker image
56+
id: push
57+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
58+
with:
59+
context: .
60+
push: true
61+
tags: ${{ steps.docker-metadata.outputs.tags }}
62+
labels: ${{ steps.docker-metadata.outputs.labels }}
63+
64+
docker-release:
65+
name: Docker Retag (Release)
66+
runs-on: ubuntu-latest
67+
needs: [prepare]
68+
container: gcr.io/go-containerregistry/crane:debug
69+
if: startsWith(github.ref, 'refs/tags/v')
70+
steps:
71+
- name: Retag and Push Images
72+
run: |
73+
crane auth login -u $USER -p $PASS $REGISTRY
74+
crane tag ${REGISTRY}/${IMAGE_NAME}:${FROM_TAG} ${TAG}
75+
env:
76+
APP_VERSION_TAG: ${{ needs.prepare.outputs.APP_VERSION_TAG }}
77+
USER: ${{ github.actor }}
78+
PASS: ${{ secrets.GITHUB_TOKEN }}
79+
REGISTRY: ${{ env.registry }}
80+
IMAGE_NAME: ${{ env.IMAGE_NAME }}
81+
FROM_TAG: ${{ needs.prepare.outputs.APP_VERSION_TAG }}
82+
TAG: ${{ github.ref_name }}
83+
84+
deploy-staging:
85+
name: Deploy to Staging
86+
needs: [prepare, docker-build]
87+
if: github.ref == 'refs/heads/enote'
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: actions/checkout@v4
91+
- run: |
92+
gh api \
93+
--method POST \
94+
-H "Accept: application/vnd.github+json" \
95+
-H "X-GitHub-Api-Version: 2022-11-28" \
96+
/repos/eNote-GmbH/helm-charts/actions/workflows/update-app-image.yml/dispatches \
97+
-f "ref=master" \
98+
-f "inputs[app]=$APP" \
99+
-f "inputs[tag]=$APP_VERSION_TAG" \
100+
-f "inputs[environment]=staging"
101+
env:
102+
GH_TOKEN: ${{ secrets.GH_PAT }}
103+
APP_VERSION_TAG: ${{ needs.prepare.outputs.APP_VERSION_TAG }}
104+
105+
deploy-prod:
106+
name: Deploy to Prod
107+
needs: [prepare, docker-release]
108+
if: startsWith(github.ref, 'refs/tags/v')
109+
runs-on: ubuntu-latest
110+
steps:
111+
- uses: actions/checkout@v4
112+
- run: |
113+
gh api \
114+
--method POST \
115+
-H "Accept: application/vnd.github+json" \
116+
-H "X-GitHub-Api-Version: 2022-11-28" \
117+
/repos/eNote-GmbH/helm-charts/actions/workflows/update-app-image.yml/dispatches \
118+
-f "ref=master" \
119+
-f "inputs[app]=$APP" \
120+
-f "inputs[tag]=$APP_VERSION_TAG" \
121+
-f "inputs[environment]=prod"
122+
env:
123+
GH_TOKEN: ${{ secrets.GH_PAT }}
124+
APP_VERSION_TAG: ${{ needs.prepare.outputs.APP_VERSION_TAG }}
125+
126+

0 commit comments

Comments
 (0)