Merge pull request #13 from dyllamt/feature/missing-string-in-actions #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.image_exists }} | |
steps: | |
- name: Check if Docker image exists with current version | |
id: check_image | |
run: | | |
VERSION=${{ needs.get-version.outputs.version }} | |
IMAGE_NAME="ghcr.io/dyllamt/coinbase-connector:$VERSION" | |
if curl -f -sL $IMAGE_NAME > /dev/null; then | |
echo "Docker image with version $VERSION exists." | |
echo "::set-output name=should_release::false" | |
else | |
echo "Docker image with version $VERSION does not exist." | |
echo "::set-output name=should_release::true" | |
fi | |
docker-push: | |
needs: [get-version, new-version-check] | |
if: needs.new-version-check.outputs.should_release == true | |
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-connector:${{ needs.get-version.outputs.version }},ghcr.io/dyllamt/coinbase-connector:latest | |
helm-release: | |
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 "[email protected]" | |
- name: Update Chart Versions | |
run: | | |
VERSION=${{ needs.prepare.outputs.version }} | |
CHARTS_DIR=charts | |
for CHART in $CHARTS_DIR/*; do | |
if [ -d "$CHART" ]; then | |
CHART_PATH="$CHART/Chart.yaml" | |
if [ -f "$CHART_PATH" ]; then | |
echo "Updating version in $CHART_PATH to $VERSION" | |
sed -i "s/version: .*/version: $VERSION/" $CHART_PATH | |
else | |
echo "No Chart.yaml found in $CHART" | |
fi | |
fi | |
done | |
- name: Release Helm Charts | |
uses: helm/[email protected] | |
with: | |
charts_dir: charts | |
env: | |
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
helm-docs: | |
needs: new-version-check | |
if: needs.new-version-check.outputs.should_release == 'true' | |
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 "[email protected]" | |
git add . | |
git commit -m "Update documentation" -a || echo "No changes to commit" | |
git push origin gh-pages |