Skip to content

Merge pull request #28 from dyllamt/feature/update-chart-ref #24

Merge pull request #28 from dyllamt/feature/update-chart-ref

Merge pull request #28 from dyllamt/feature/update-chart-ref #24

name: Release Artifacts
on:
push:
branches:
- main
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Extract version from file
id: extract_version
run: echo "::set-output name=version::$(cat VERSION)"
new-version-check:
needs: get-version
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check_image.outputs.should_release }}
steps:
- name: Check if Docker image exists with current version
id: check_image
env:
VERSION: ${{ needs.get-version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REGISTRY="ghcr.io"
REPO="dyllamt/coinbase-producer"
TAG="$VERSION"
MANIFEST_URL="https://$REGISTRY/v2/$REPO/manifests/$TAG"
AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN"
ACCEPT_HEADER="Accept: application/vnd.docker.distribution.manifest.v2+json"
HEADERS="-H \"$ACCEPT_HEADER\" -H \"$AUTH_HEADER\""
CURL_OPTIONS="-f -sL"
if curl $CURL_OPTIONS $HEADERS "$MANIFEST_URL" > /dev/null; then
echo "Docker image with version $VERSION exists."
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Docker image with version $VERSION does not exist."
echo "should_release=true" >> $GITHUB_OUTPUT
fi
docker-push:
needs: [get-version, new-version-check]
if: ${{ needs.new-version-check.outputs.should_release == 'true' }}
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/dyllamt/coinbase-producer:${{ needs.get-version.outputs.version }},ghcr.io/dyllamt/coinbase-producer:latest
helm-push:
needs: [get-version, new-version-check]
if: ${{ needs.new-version-check.outputs.should_release == 'true' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: '3.13.3'
- name: Log in to the OCI Registry
run: helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
- name: Package and Push coinbase-kafka Chart as OCI Artifact
run: |
VERSION=${{ needs.get-version.outputs.version }}
CHART_NAME="coinbase-kafka"
CHART_PATH="charts/$CHART_NAME"
CHART_REF="oci://ghcr.io/dyllamt/charts/$CHART_NAME:$VERSION"
# Update Chart.yaml version
sed -i "s/version: .*/version: $VERSION/" "$CHART_PATH/Chart.yaml"
# Package and push
helm package $CHART_PATH --version $VERSION --app-version $VERSION
helm push $CHART_NAME-$VERSION.tgz $CHART_REF
- name: Package and Push coinbase-producer Chart as OCI Artifact
run: |
VERSION=${{ needs.get-version.outputs.version }}
CHART_NAME="coinbase-producer"
CHART_PATH="charts/$CHART_NAME"
CHART_REF="oci://ghcr.io/dyllamt/charts/$CHART_NAME:$VERSION"
IMAGE_TAG="ghcr.io/dyllamt/$CHART_NAME:$VERSION"
# Update Chart.yaml version
sed -i "s/version: .*/version: $VERSION/" "$CHART_PATH/Chart.yaml"
# Update values.yaml image tag
sed -i "s|image: .*|image: $IMAGE_TAG|" "$CHART_PATH/values.yaml"
# Package and push
helm package $CHART_PATH --version $VERSION --app-version $VERSION
helm push $CHART_NAME-$VERSION.tgz $CHART_REF
helm-docs:
needs: [get-version, new-version-check]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: 'main'
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Generate Documentation
run: |
go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
cd charts
for d in */ ; do
helm-docs -c $d
done
- name: Checkout gh-pages Branch
uses: actions/checkout@v3
with:
ref: 'gh-pages'
path: 'gh-pages'
- name: Copy Documentation to gh-pages
run: |
for CHART_DIR in charts/*; do
if [ -d "$CHART_DIR" ]; then # Ensure it's a directory
CHART_NAME=$(basename $CHART_DIR)
# Create a matching directory structure in gh-pages
mkdir -p gh-pages/$CHART_NAME
# Copy the README.md for the chart
cp $CHART_DIR/README.md gh-pages/$CHART_NAME/
fi
done
- name: Commit and Push Changes to gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd gh-pages
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add .
git commit -m "Update documentation" -a || echo "No changes to commit"
git push origin gh-pages