Skip to content

Commit

Permalink
Merge pull request #8 from sgibson91/publishing-charts
Browse files Browse the repository at this point in the history
Use chartpress to publish helm chart to gh-pages branch
  • Loading branch information
sgibson91 authored Sep 13, 2024
2 parents 808320a + b7d90a8 commit a449041
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 66 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/publish-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build and Publish Docker Image and Helm Chart

on:
workflow_dispatch:
push:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/publish-chart.yaml"
pull_request:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/publish-chart.yaml"

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"
):
publish = "true"
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: Run 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"
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}"
git --no-pager diff --color
66 changes: 0 additions & 66 deletions .github/workflows/publish.yaml

This file was deleted.

0 comments on commit a449041

Please sign in to comment.