helm / chart-releaser-action

A GitHub Action to turn a GitHub project into a self-hosted Helm chart repo, using helm/chart-releaser CLI tool
https://github.com/helm/chart-releaser
Apache License 2.0
573 stars 209 forks source link

feat: Add json output #95

Open stevehipwell opened 3 years ago

stevehipwell commented 3 years ago

I'd like to be able drive further actions from the output of the chart releaser action. My suggested implementation would be to return json in the format `[{"chart": "my-chart", "version": "1.0.0", "tag": "my-chart-1.0.0"}].

This output could then be used to drive a matrix. See below for an example of updating the release notes with a CHANGELOG entry (for https://github.com/helm/chart-releaser-action/issues/44).

name: Release Charts

on:
  push:
    branches:
      - main

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        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: Install Helm
        uses: azure/setup-helm@v1
        with:
          version: v3.4.0

      - name: Run chart-releaser
        id: release_step
        uses: helm/chart-releaser-action@v1.2.1
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

    outputs:
       versions: ${{ steps.release_step.outputs.releases }}

  changelog:
    needs: release
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include: ${{ fromJson(needs.release.outputs.versions) }}
    steps:
      - name: Get changelog entry
        id: changelog_reader
        uses: mindsers/changelog-reader-action@v2
        with:
          path: ./charts/${{matrix.chart}}/CHANGELOG.md
          version: "v${{matrix.version}}"

      - name: Update release
        uses: ncipollo/release-action@v1
        with:
          allowUpdates: true
          body: ${{ steps.changelog_reader.outputs.changes }}
          tag: ${{matrix.tag}}
          token: ${{ secrets.GITHUB_TOKEN }}
pete911 commented 2 years ago

hi @stevehipwell, I've created another project that can be used as github action and it implements the json output you requested. The project is https://github.com/pete911/hcr and there is an example of how to use it as github action.

It logs to stderr, but the result in json is printed in stdout, so you can just run it as hcr 2> /dev/null to get only json output.