-
Notifications
You must be signed in to change notification settings - Fork 14
122 lines (103 loc) · 3.69 KB
/
Copy pathrelease.yml
File metadata and controls
122 lines (103 loc) · 3.69 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
name: Release to GHCR & Helm Sync
on:
pull_request:
paths:
- pyproject.toml
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.check.outputs.should_skip }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if pyproject.toml version changed
id: check
run: |
if git rev-parse HEAD^ >/dev/null 2>&1; then
DIFF=$(git diff -U0 HEAD^ -- pyproject.toml)
else
DIFF=$(git show HEAD:pyproject.toml)
fi
echo "DIFF=$DIFF"
if echo "$DIFF" | grep -E '^+\s*version\s*='; then
echo "should_skip=false" >> $GITHUB_OUTPUT
echo "Detected version change. should_skip=false"
else
echo "should_skip=true" >> $GITHUB_OUTPUT
echo "No version change found. should_skip=true"
fi
build-and-push:
name: Build & Push to GHCR using pyproject version
needs: check-version
if: needs.check-version.outputs.should_skip != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
GHCR_IMAGE: ghcr.io/${{ github.repository }}
outputs:
version: ${{ steps.version.outputs.VERSION }}
image: ${{ steps.version.outputs.IMAGE }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(grep -Po '(?<=^version = ")[^"]+' pyproject.toml)
echo "VERSION=$VERSION"
echo "VERSION_TAG=v$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "IMAGE=${{ env.GHCR_IMAGE }}" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker image to GHCR
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.GHCR_IMAGE }}:${{ env.VERSION_TAG }}
update-helm-values:
name: Update Helm Values
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "${{ github.head_ref || github.ref_name }}"
fetch-depth: 0 # important for PR creation
- name: Set up Git config
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Define file paths
id: files
run: |
echo "CHART_FILE=deployments/model-serving/Chart.yaml" >> $GITHUB_ENV
echo "VALUE_FILE=deployments/model-serving/values.yaml" >> $GITHUB_ENV
- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Update Chart.yaml & values.yaml with version
run: |
VERSION="v${{ needs.build-and-push.outputs.version }}"
IMAGE="${{ needs.build-and-push.outputs.image }}"
yq eval ".version = \"${VERSION#v}\" |
.appVersion = \"${VERSION#v}\"" \
-i "$CHART_FILE"
yq eval ".image.repository = \"$IMAGE\" |
.image.tag = \"$VERSION\"" \
-i "$VALUE_FILE"
git add "$CHART_FILE" "$VALUE_FILE"
git commit -m "ci: update Helm values.yaml and Chart.yaml to $IMAGE:$VERSION"
git push origin HEAD