fix: add namespaces to helmchart (#4598) #2
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: Helm chart | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'charts/**' | |
pull_request: | |
branches: | |
- 'main' | |
paths: | |
- 'charts/**' | |
workflow_dispatch: | |
permissions: | |
contents: read # for actions/checkout to fetch code | |
jobs: | |
helm-new-version: | |
runs-on: ubuntu-latest | |
outputs: | |
old-version: ${{ steps.old-version.outputs.version }} | |
new-version: ${{ steps.new-version.outputs.version }} | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Find new version | |
id: new-version | |
run: | | |
NEW_VERSION=$(yq e '.version' charts/gitops-server/Chart.yaml) | |
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Find old version | |
id: old-version | |
run: | | |
git checkout ${{ github.event.pull_request.base.sha || github.event.before }} | |
OLD_VERSION=$(yq e '.version' charts/gitops-server/Chart.yaml) | |
echo "version=$OLD_VERSION" >> $GITHUB_OUTPUT | |
helm-will-release: | |
runs-on: ubuntu-latest | |
needs: helm-new-version | |
if: github.event_name == 'pull_request' && needs.helm-new-version.outputs.old-version != needs.helm-new-version.outputs.new-version | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Find out if there's more changes to release | |
id: extra | |
run: | | |
last_revision=$(git blame ${{ github.event.pull_request.base.sha }} -L '/^version: [0-9.]\+$/,+1' charts/gitops-server/Chart.yaml | awk '{print $1}') | |
set +e | |
git log --exit-code $last_revision...${{ github.event.pull_request.base.sha }} charts/gitops-server | |
unreleased_commits=$? | |
if [[ $unreleased_commits == 1 ]]; then | |
echo "unreleased-commits=The last chart was last released in $last_revision and there have been other changes in the chart since" >> $GITHUB_OUTPUT | |
fi | |
- name: Let user know merging will cause a release | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
github-token: ${{ secrets.WEAVE_GITOPS_BOT_ACCESS_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: "Merging this will release a new helm chart. ${{ steps.extra.outputs.unreleased-commits }}" | |
}) | |
helm-release: | |
runs-on: ubuntu-latest | |
needs: helm-new-version | |
if: (github.event_name == 'push' && needs.helm-new-version.outputs.old-version != needs.helm-new-version.outputs.new-version) || github.event_name == 'workflow_dispatch' | |
permissions: | |
packages: write # needed for ghcr access | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Find new version | |
id: new_version | |
run: | | |
NEW_VERSION=$(yq e '.version' charts/gitops-server/Chart.yaml) | |
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Generate new chart | |
run: | | |
mkdir helm-release | |
helm package charts/gitops-server/ -d helm-release | |
- name: Log in to the Container registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish chart as an OCI image | |
run: | | |
helm push helm-release/weave-gitops-${{ steps.new_version.outputs.version }}.tgz oci://ghcr.io/weaveworks/charts |