Repository navigation
169 lines (151 loc) · 4.98 KB
/
Copy pathci-cd.yml
File metadata and controls
169 lines (151 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
semantic-release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
version: ${{ steps.release.outputs.version }}
released: ${{ steps.release.outputs.released }}
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
- name: Install semantic-release
run: |
npm install -g semantic-release @semantic-release/changelog @semantic-release/git
- name: Release
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx semantic-release --debug 2>&1 | tee release.log
if grep -q "Published release" release.log; then
VERSION=$(grep "Published release" release.log | sed -n 's/.*Published release \([^ ]*\).*/\1/p')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "released=true" >> $GITHUB_OUTPUT
else
echo "released=false" >> $GITHUB_OUTPUT
fi
docker-build:
runs-on: ubuntu-latest
needs: [semantic-release]
if: github.ref == 'refs/heads/main' && needs.semantic-release.outputs.released == 'true'
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- image: patchnotes-admin
dockerfile: admin/Dockerfile
context: .
- image: patchnotes-mkdocs
dockerfile: mkdocs/Dockerfile
context: mkdocs
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.image }}
tags: |
type=raw,value=latest
type=raw,value=${{ needs.semantic-release.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
helm-push:
runs-on: ubuntu-latest
needs: [semantic-release]
if: github.ref == 'refs/heads/main' && needs.semantic-release.outputs.released == 'true'
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Update chart version and image tags
run: |
VERSION=${{ needs.semantic-release.outputs.version }}
sed -i "s/^version:.*/version: ${VERSION}/" .helm/Chart.yaml
sed -i "s/^appVersion:.*/appVersion: \"${VERSION}\"/" .helm/Chart.yaml
sed -i "s/ tag: latest/ tag: ${VERSION}/" .helm/values.yaml
- name: Package and push
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
helm package .helm/
helm push patchnotes-*.tgz oci://ghcr.io/${OWNER}/charts
sync-develop:
runs-on: ubuntu-latest
needs: [semantic-release]
if: github.ref == 'refs/heads/main'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
ref: main
- name: Create sync PR
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
BRANCH_NAME="sync-main-to-develop-$(date +%s)"
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME
PR_URL=$(gh pr create \
--title "chore: sync release changes from main to develop" \
--body "Auto-sync after release. This PR merges the latest changes from main branch to develop." \
--base develop \
--head $BRANCH_NAME)
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
- name: Enable auto-merge
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
gh pr merge --auto --merge "$PR_URL"