-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (90 loc) · 3.05 KB
/
publish-chart.yaml
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
name: Build and Publish Docker Image and Helm Chart
on:
workflow_dispatch:
push:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/publish-chart.yaml"
branches:
- "main"
pull_request:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/publish-chart.yaml"
tags:
- "**"
jobs:
publish-chart:
runs-on: ubuntu-latest
# Give explicit permission for GITHUB_TOKEN to write to this repo's gh-pages branch
permissions:
contents: write
steps:
- name: Decide to publish the chart or not
id: publish
shell: python
run : |
import os
publish = ""
if (
"${{ github.repository }}" == "2i2c-org/gcp-filestore-backups"
and "${{ github.event_name }}" == "push"
and (
"${{ github.event.ref }}" == "refs/heads/main"
or "${{ github.event.ref }}".startswith("refs/tags/")
)
):
publish = "true"
print("Publishing chart")
output_file = os.getenv("GITHUB_OUTPUT")
with open(output_file, "w") as f:
f.write(f"publish={publish}\n")
- name: Checkout repo
uses: actions/checkout@v4
with:
# chartpress requires full history
fetch-depth: 0
- name: Login to quay.io
if: steps.publish.outputs.publish
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: pip install chartpress
- name: Configure a git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions user"
- name: Build image, push if necessary
env:
PUBLISH: ${{ steps.publish.outputs.publish }}
run: |
CHARTPRESS_ARGS=""
if [[ "${PUBLISH}" == "true" ]]; then
CHARTPRESS_ARGS="--push"
fi
chartpress ${CHARTPRESS_ARGS}
- name: Publish helm chart with chartpress
if: steps.publish.outputs.publish
env:
GITHUB_TOKEN: "${{ github.token }}"
run: |
set -eux
PUBLISH_ARGS="--publish-chart --push"
if [[ $GITHUB_REF != refs/tags/* ]]; then
PR_OR_HASH=$(git log -1 --pretty=%h-%B | head -n1 | sed 's/^.*\(#[0-9]*\).*/\1/' | sed 's/^\([0-9a-f]*\)-.*/@\1/')
LATEST_COMMIT_TITLE=$(git log -1 --pretty=%B | head -n1)
EXTRA_MESSAGE="${{ github.repository }}${PR_OR_HASH} ${LATEST_COMMIT_TITLE}"
chartpress $PUBLISH_ARGS --extra-message "${EXTRA_MESSAGE}"
else
chartpress $PUBLISH_ARGS --tag "${GITHUB_REF:10}"
fi
git --no-pager diff --color