Skip to content

Commit 9ea45bf

Browse files
committed
refactor(ci): use composite action for detect logic
1 parent 4ffc8cf commit 9ea45bf

3 files changed

Lines changed: 59 additions & 49 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Detect chart versions and releases
2+
description: Read appVersion and version from Chart.yaml and report whether the corresponding GitHub releases already exist.
3+
4+
inputs:
5+
chart-dir:
6+
description: Path to the Helm chart directory
7+
required: false
8+
default: deploy/helm
9+
10+
outputs:
11+
app_version:
12+
description: The chart's appVersion
13+
value: ${{ steps.detect.outputs.app_version }}
14+
chart_version:
15+
description: The chart's version
16+
value: ${{ steps.detect.outputs.chart_version }}
17+
app_release_exists:
18+
description: "true if a GitHub release named <app_version> already exists"
19+
value: ${{ steps.detect.outputs.app_release_exists }}
20+
chart_release_exists:
21+
description: "true if a GitHub release named helm-v<chart_version> already exists"
22+
value: ${{ steps.detect.outputs.chart_release_exists }}
23+
24+
runs:
25+
using: composite
26+
steps:
27+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
28+
29+
- name: Detect versions and releases
30+
id: detect
31+
shell: bash
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
CHART_DIR: ${{ inputs.chart-dir }}
35+
run: |
36+
app_version=$(yq .appVersion "$CHART_DIR/Chart.yaml")
37+
chart_version=$(yq .version "$CHART_DIR/Chart.yaml")
38+
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
39+
echo "chart_version=$chart_version" >> "$GITHUB_OUTPUT"
40+
41+
if gh release view "$app_version" > /dev/null 2>&1; then
42+
echo "app_release_exists=true" >> "$GITHUB_OUTPUT"
43+
else
44+
echo "app_release_exists=false" >> "$GITHUB_OUTPUT"
45+
fi
46+
47+
if gh release view "helm-v$chart_version" > /dev/null 2>&1; then
48+
echo "chart_release_exists=true" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "chart_release_exists=false" >> "$GITHUB_OUTPUT"
51+
fi

.github/workflows/release-app.yaml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,11 @@ jobs:
3030
timeout-minutes: 5
3131
runs-on: ubuntu-24.04
3232
outputs:
33-
skip: ${{ steps.detect.outputs.skip }}
33+
skip: ${{ steps.detect.outputs.app_release_exists }}
3434
app_version: ${{ steps.detect.outputs.app_version }}
3535
steps:
36-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37-
38-
- name: Detect appVersion bump
39-
id: detect
40-
env:
41-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
run: |
43-
app_version=$(yq .appVersion "$CHART_DIR/Chart.yaml")
44-
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
45-
46-
if gh release view "$app_version" > /dev/null 2>&1; then
47-
echo "Release $app_version already exists. Skipping."
48-
echo "skip=true" >> "$GITHUB_OUTPUT"
49-
exit 0
50-
fi
51-
52-
echo "skip=false" >> "$GITHUB_OUTPUT"
36+
- id: detect
37+
uses: ./.github/actions/detect-versions
5338

5439
build-image:
5540
needs: detect
@@ -115,7 +100,6 @@ jobs:
115100
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
116101
with:
117102
image: ${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.detect.outputs.app_version }}
118-
format: spdx-json
119103
output-file: sbom.spdx.json
120104
upload-artifact: false
121105
upload-release-assets: false

.github/workflows/release-helm.yaml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,12 @@ jobs:
3030
detect:
3131
runs-on: ubuntu-24.04
3232
outputs:
33-
skip: ${{ steps.check.outputs.skip_release }}
34-
chart_version: ${{ steps.check.outputs.chart_version }}
35-
app_version_bumped: ${{ steps.check.outputs.app_version_bumped }}
33+
skip: ${{ steps.detect.outputs.chart_release_exists }}
34+
chart_version: ${{ steps.detect.outputs.chart_version }}
35+
app_version_bumped: ${{ steps.detect.outputs.app_release_exists == 'false' }}
3636
steps:
37-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38-
with:
39-
fetch-depth: 0
40-
41-
- name: Check version bump
42-
id: check
43-
env:
44-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45-
run: |
46-
chart_version=$(yq .version "$CHART_DIR/Chart.yaml")
47-
app_version=$(yq .appVersion "$CHART_DIR/Chart.yaml")
48-
echo "chart_version=$chart_version" >> "$GITHUB_OUTPUT"
49-
50-
if gh release view "helm-v$chart_version" > /dev/null 2>&1; then
51-
echo "Release helm-v$chart_version already exists. Skipping."
52-
echo "skip_release=true" >> "$GITHUB_OUTPUT"
53-
exit 0
54-
fi
55-
56-
echo "skip_release=false" >> "$GITHUB_OUTPUT"
57-
58-
if gh release view "$app_version" > /dev/null 2>&1; then
59-
echo "app_version_bumped=false" >> "$GITHUB_OUTPUT"
60-
else
61-
echo "Release $app_version has changed. Leaving E2E tests to release-app action."
62-
echo "app_version_bumped=true" >> "$GITHUB_OUTPUT"
63-
fi
37+
- id: detect
38+
uses: ./.github/actions/detect-versions
6439

6540
# The E2E tests are run when the chart version is bumped, but will be skipped if the appVersion
6641
# has been bumped as well. The release-app action will then run the E2E tests instead.

0 commit comments

Comments
 (0)