CI / Release #137
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: CI / Release | |
on: | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
test: | |
name: Lint and Build Helm chart | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
check-latest: true | |
- name: Set up chart-testing | |
uses: helm/[email protected] | |
- name: Run helm unit tests | |
run: | | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
helm plugin install https://github.com/helm-unittest/helm-unittest.git | |
helm unittest ./ | |
- name: Create testing cluster | |
uses: helm/[email protected] | |
- name: Run chart-testing (lint) | |
run: ct lint --target-branch ${{ github.event.repository.default_branch }} --charts ./ | |
- name: Run chart-testing (install) | |
run: ct install --target-branch ${{ github.event.repository.default_branch }} --charts ./ | |
publish: | |
name: Publish Helm chart | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.event_name == 'workflow_dispatch' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Fetch history | |
run: git fetch --prune --unshallow | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
- name: Set the version | |
run: echo "VERSION=$(grep '^version:' ./Chart.yaml| awk '{print $2}')" >> $GITHUB_ENV | |
- name: Package the chart | |
run: helm package . --destination .release-packages --dependency-update | |
- name: Prep release notes | |
run: | | |
release_notes=`sed -n '/^## \['v${{ env.VERSION }}'\]/,/^## /p' CHANGELOG.md | sed -n '/^- /p'` | |
echo "RELEASE NOTES: $release_notes" | |
echo "$release_notes" > body.md | |
release_name=`echo "$release_notes"| head -1 | sed 's/^- //'` | |
echo "RELEASE_NAME=$release_name" >> $GITHUB_ENV | |
- name: Make the release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: v${{ env.VERSION }} | |
release_name: ${{ env.RELEASE_NAME }} | |
body_path: body.md | |
- name: upload artifacts to the release | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./.release-packages/puppetserver-${{ env.VERSION }}.tgz | |
asset_name: puppetserver-${{ env.VERSION }}.tgz | |
asset_content_type: application/gzip | |
- name: update ghpages | |
run: | | |
gh_pages_worktree=$(mktemp -d) | |
git worktree add "$gh_pages_worktree" gh-pages | |
cp .release-packages/puppetserver-${{ env.VERSION }}.tgz $gh_pages_worktree | |
cp CHANGELOG.md README.md LICENSE CODEOWNERS $gh_pages_worktree | |
find "$gh_pages_worktree" -type f ! -name "puppetserver-${{ env.VERSION }}.tgz" -name 'puppetserver*.tgz' -delete | |
helm repo index $gh_pages_worktree --url https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }} --merge "$gh_pages_worktree/index.yaml" | |
pushd "$gh_pages_worktree" > /dev/null | |
git add index.yaml puppetserver-${{ env.VERSION }}.tgz | |
git commit --message "puppetserver-${{ env.VERSION }} release" | |
git checkout 'puppetserver*.tgz' # reset the files removed to make the index accurate | |
git commit --all --message "Sync files from master branch" ||: | |
repo_url="https://x-access-token:[email protected]/${{ github.repository }}" | |
git push "$repo_url" gh-pages | |
popd > /dev/null |