From 85b3f380bc5022d393e799d79d0dfa6eeafd343b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= Date: Sun, 31 Jul 2022 12:18:56 +0200 Subject: [PATCH] Split chart release flow (#13) --- .github/workflows/charts-release-ghpages.yaml | 82 +++++++++++++++++++ .github/workflows/charts-release.yaml | 76 ++++------------- 2 files changed, 98 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/charts-release-ghpages.yaml diff --git a/.github/workflows/charts-release-ghpages.yaml b/.github/workflows/charts-release-ghpages.yaml new file mode 100644 index 00000000..d0f71592 --- /dev/null +++ b/.github/workflows/charts-release-ghpages.yaml @@ -0,0 +1,82 @@ +name: "Charts: Release to GitHub pages" + +concurrency: helm-release + +on: + workflow_call: + inputs: + token: + required: true + default: "${{ github.token }}" + description: "The Github API token to use" + type: string + charts: + description: > + Json encoded list of Helm charts to release. + Defaults to releasing everything. + default: "[]" + required: false + type: string + +env: + HELM_VERSION: 3.9.2 + +jobs: + release-charts: + name: Release charts + runs-on: ubuntu-22.04 + steps: + - name: Checkout charts branch + uses: actions/checkout@v3 + with: + token: ${{ inputs.token }} + path: "src" + fetch-depth: 0 + + - name: Checkout gh-pages branch + uses: actions/checkout@v3 + with: + token: ${{ inputs.token }} + path: "dest" + ref: "gh-pages" + fetch-depth: 0 + + - name: Install Kubernetes tools + uses: yokawasa/action-setup-kube-tools@v0.8.2 + with: + setup-tools: | + helmv3 + helm: "${{ env.HELM_VERSION }}" + + - name: Package Helm Charts + shell: bash + env: + SRC_DIR: "src/charts" + DEST_DIR: "dest" + run: | + CHARTS=( $(yq --null-input e '${{ inputs.charts }}[]' ) ) + + for CHART in "${CHARTS[@]}" ; do + mapfile -t CHART_PATH_PARTS < <(echo "$CHART" | tr '/' '\n') + CHART_TYPE=${CHART_PATH_PARTS[0]} + + helm dep up "${SRC_DIR}/${CHART}" + helm package "${SRC_DIR}/${CHART}" -u -d "${DEST_DIR}/${CHART_TYPE}" + done + + - name: Update chart index + shell: bash + working-directory: dest + run: | + helm repo index . --url https://bjw-s.github.io/helm-charts/ + + - name: Commit changes + shell: bash + working-directory: dest + run: | + git config user.name "bjw-s-bot[bot]" + git config user.email "bjw-s-bot <87358111+bjw-s-bot[bot]@users.noreply.github.com>" + git add $(git ls-files -o --exclude-standard) + git add index.yaml + git commit -m "Updated from ref: $GITHUB_SHA" + git push diff --git a/.github/workflows/charts-release.yaml b/.github/workflows/charts-release.yaml index 6395664a..ab5bc83e 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -5,9 +5,9 @@ concurrency: helm-release on: workflow_dispatch: inputs: - chart: + charts: description: > - Chart to release. Comma-separated string. + Charts to release. Comma-separated string. Defaults to releasing everything. default: "" required: false @@ -21,9 +21,12 @@ env: HELM_VERSION: 3.9.2 jobs: - release-charts: - name: Release charts + prepare: + name: Prepare data required for release runs-on: ubuntu-22.04 + outputs: + token: ${{ steps.get-app-token.outputs.token }} + charts-to-release: ${{ steps.collect-charts.outputs.charts }} steps: - name: Get k8s-at-home token id: get-app-token @@ -32,65 +35,18 @@ jobs: app_id: ${{ secrets.BJWS_APP_ID }} private_key: ${{ secrets.BJWS_APP_PRIVATE_KEY }} - - name: Checkout charts branch - uses: actions/checkout@v3 - with: - token: ${{ steps.get-app-token.outputs.token }} - path: "src" - fetch-depth: 0 - - name: Collect charts to release uses: ./src/.github/actions/collect-charts id: collect-charts with: - token: ${{ steps.get-app-token.outputs.token }} + token: ${{ inputs.token }} repoConfigFile: ./src/.ci/repo-config.yaml - overrideCharts: "[${{ inputs.chart }}]" + overrideCharts: "[${{ inputs.charts }}]" - - name: Checkout gh-pages branch - uses: actions/checkout@v3 - with: - token: ${{ steps.get-app-token.outputs.token }} - path: "dest" - ref: "gh-pages" - fetch-depth: 0 - - - name: Install Kubernetes tools - uses: yokawasa/action-setup-kube-tools@v0.8.2 - with: - setup-tools: | - helmv3 - helm: "${{ env.HELM_VERSION }}" - - - name: Package Helm Charts - shell: bash - env: - SRC_DIR: "src/charts" - DEST_DIR: "dest" - run: | - CHARTS=( $(yq --null-input e '${{ steps.collect-charts.outputs.charts }}[]' ) ) - - for CHART in "${CHARTS[@]}" ; do - mapfile -t CHART_PATH_PARTS < <(echo "$CHART" | tr '/' '\n') - CHART_TYPE=${CHART_PATH_PARTS[0]} - - helm dep up "${SRC_DIR}/${CHART}" - helm package "${SRC_DIR}/${CHART}" -u -d "${DEST_DIR}/${CHART_TYPE}" - done - - - name: Update chart index - shell: bash - working-directory: dest - run: | - helm repo index . --url https://bjw-s.github.io/helm-charts/ - - - name: Commit changes - shell: bash - working-directory: dest - run: | - git config user.name "bjw-s-bot[bot]" - git config user.email "bjw-s-bot <87358111+bjw-s-bot[bot]@users.noreply.github.com>" - git add $(git ls-files -o --exclude-standard) - git add index.yaml - git commit -m "Updated from ref: $GITHUB_SHA" - git push + release-github-pages: + name: Release Charts to GitHub pages + uses: bjw-s/helm-charts/.github/workflows/charts-release-ghpages.yaml@main + needs: + - prepare + with: + charts: "[${{ needs.prepare.outputs.charts-to-release }}]"