Skip to content

Commit

Permalink
refactor publish storm charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ljubon committed Aug 26, 2021
1 parent 925ee0a commit 52ec3b1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/publish-charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ on:
description: 'Repository from where we want to build Charts'
required: true
repo_ref:
description: 'The branch or tag ref that triggered the workflow'
description: 'The branch/tag that will be used as new version for charts. Usually tag ref'
required: true
repo_chart:
description: 'Object with source, destination and chart name'
description: 'Object with source path, destination path and chart name'
required: true
currentChartVersion:
description: 'Chart version set in `Chart.yaml`. Default: `LATEST`'
Expand Down Expand Up @@ -45,27 +45,28 @@ jobs:
ref: ${{ env.REPO_REF }}
path: ${{ env.REPO }}

- id: chart-version
name: 'Set version - ${{ env.REPO_REF }}'
if: ${{ steps.checkout-gh-pages.outcome == 'success' && steps.checkout-helm-src.outcome == 'success' }}
run: |
find . \( -name "Chart.yaml" -o -name "values.yaml" \) -exec sed -i s/${{ env.CurrentChartVersion }}/${{ env.REPO_REF }}/ {} +
echo "Replacing ${{ env.CurrentChartVersion }} with new version ${{ env.REPO_REF }}."
working-directory: ./${{ env.REPO }}

- id: check
name: 'Check if chart already exist'
if: ${{ steps.checkout-gh-pages.outcome == 'success' && steps.checkout-helm-src.outcome == 'success' }}
if: ${{ steps.chart-version.outcome == 'success' }}
run: |
FILE=$(grep name ${{ env.REPO }}/${{ matrix.src_path }}Chart.yaml | awk '{print $2}')
if [[ -f "${{ matrix.dst_path }}$FILE-${{ env.REPO_REF }}.tgz" ]]; then
echo "Chart already exists."
echo "${{ matrix.dst_path }}$FILE-${{ env.REPO_REF }}.tgz"
ls -larth ${{ matrix.dst_path }}
exit 1
else
echo "File doesn't exist, continue with packaging"
fi
- id: chart-version
name: 'Set version - ${{ env.REPO_REF }}'
if: ${{ steps.check.outcome == 'success' }}
run: |
find . \( -name "Chart.yaml" -o -name "values.yaml" \) -exec sed -i s/${{ env.CurrentChartVersion }}/${{ env.REPO_REF }}/ {} +
echo "Replacing ${{ env.CurrentChartVersion }} with new version ${{ env.REPO_REF }}"
working-directory: ./${{ env.REPO }}

- id: package
name: Package ${{ matrix.chart }}-${{ env.REPO_REF }}.tgz
if: ${{ steps.chart-version.outcome == 'success' && steps.check.outcome == 'success' }}
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/storm-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

name: publish-storm

on:
push:
paths:
- 'storm/**'
tags:
- '*'

defaults:
run:
shell: bash

jobs:

publish-charts:
name: Publish charts
if: ${{ startsWith(github.ref, 'refs/tags/') }} # Storm charts are publishied without `v` in front of version
runs-on: ubuntu-20.04
steps:
- name: Install Step
env:
VERSION: 0.15.16
run: |
curl -sLO https://github.com/smallstep/cli/releases/download/v${VERSION}/step-cli_${VERSION}_amd64.deb
sudo dpkg -i step-cli_${VERSION}_amd64.deb
rm step-cli_${VERSION}_amd64.deb
- name: Acquire access token
id: token
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PEM: ${{ secrets.GH_APP_PEM }}
INSTALLATION_ID: ${{ secrets.INSTALLATION_ID }}
run: |
echo "$APP_PEM" > key.pem
trap "rm -f key.pem" EXIT
APP_TOKEN=$(step crypto jwt sign --key key.pem --issuer $APP_ID --expiration $(date --date '+5 min' +'%s') --subtle </dev/null)
ACCESS_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization:Bearer $APP_TOKEN" https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens | jq -r '.token')
echo "::set-output name=token::$ACCESS_TOKEN"
- name: Publish chart
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
GH_WORKFLOW: "publish-charts.yaml" # workflow to execute
GH_CHART_REPO: "ljubon/charts" # owner/repo where charts are published
GH_PAGES_BRANCH: "WIP-refactor-gh-pages" # gh-pages
REPO: "ljubon/charts" # Repository from where we want to build Charts
REPO_REF: ${GITHUB_REF##*/} # The branch/tag that triggered the workflow
CurrentChartVersion: "1.0.11" # Chart version set in `Chart.yaml`. Default: `LATEST`
REPO_CHART: |
'{
"include": [
{
"chart": "storm",
"src_path": "storm/",
"dst_path": "storm/"
}
]
}'
run: |
gh workflow run ${{ env.GH_WORKFLOW }} --repo ${{ env.GH_CHART_REPO }} --ref ${{ env.GH_PAGES_BRANCH }} \
--field repo=${{ env.REPO }} \
--field repo_ref=${{ env.REPO_REF }} \
--field currentChartVersion=${{ env.CurrentChartVersion }} \
--field repo_chart=${{ env.REPO_CHART }}

0 comments on commit 52ec3b1

Please sign in to comment.