This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-07-26 21:56:16 +02:00
parent ad184ab678
commit f5a67d0150
No known key found for this signature in database
GPG key ID: BC5E2BD907F9A8EC
10 changed files with 387 additions and 0 deletions

View file

@ -0,0 +1,45 @@
name: "Collect changes"
description: "Collects and stores changed files/charts"
outputs:
changesDetected:
description: "Whether or not changes to charts have been detected"
value: ${{ steps.filter.outputs.addedOrModified }}
addedOrModifiedFiles:
description: "A list of the files changed"
value: ${{ steps.filter.outputs.addedOrModified_files }}
addedOrModifiedCharts:
description: "A list of the charts changed"
value: ${{ steps.filter-charts.outputs.addedOrModified }}
runs:
using: "composite"
steps:
- name: Collect changed files
uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: 'charts/*/**'
- name: Collect changed charts
if: |
steps.filter.outputs.addedOrModified == 'true'
id: filter-charts
shell: bash
run: |
CHARTS=()
PATHS=(${{ steps.filter.outputs.addedOrModified_files }})
# Get only the chart paths
for CHARTPATH in "${PATHS[@]}"
do
IFS='/' read -r -a path_parts <<< "${CHARTPATH}"
CHARTS+=("${path_parts[1]}/${path_parts[2]}")
done
# Remove duplicates
CHARTS=( `printf "%s\n" "${CHARTS[@]}" | sort -u` )
# Set output to changed charts
printf "::set-output name=addedOrModified::%s\n" "${CHARTS[*]}"

View file

@ -0,0 +1,48 @@
name: "Set issue labels based on status"
description: "Sets / removes issue labels based on CI job status"
inputs:
token:
required: true
description: "The Github API token to use"
issue-number:
required: true
description: "The issue to label"
prefix:
required: true
description: "The label prefix (e.g. lint, install)"
job-status:
required: true
description: "The status of the CI job"
remove-on-skipped:
required: false
default: "false"
description: "Remove the label if the job was skipped"
runs:
using: "composite"
steps:
- name: Label success
uses: andymckay/labeler@1.0.4
if: ${{ inputs.job-status == 'success' }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
add-labels: "${{ inputs.prefix }}:ok"
remove-labels: "${{ inputs.prefix }}:failed"
- name: Label failure
uses: andymckay/labeler@1.0.4
if: ${{ inputs.job-status == 'failure' }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
add-labels: "${{ inputs.prefix }}:failed"
remove-labels: "${{ inputs.prefix }}:ok"
- name: Remove label
uses: andymckay/labeler@1.0.4
if: ${{ (inputs.job-status == 'skipped') && (inputs.remove-on-skipped == 'true') }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
remove-labels: "${{ inputs.prefix }}:ok, ${{ inputs.prefix }}:failed"

53
.github/workflows/charts-lint-test.yaml vendored Normal file
View file

@ -0,0 +1,53 @@
name: "Charts: Lint"
on:
workflow_call:
inputs:
checkoutCommit:
required: true
type: string
chartChangesDetected:
required: true
type: string
jobs:
lint:
name: Lint charts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.8.2
with:
setup-tools: |
helmv3
helm: "3.8.0"
- name: Install Helm
uses: Azure/setup-helm@v3.3
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
- name: Collect changes
id: list-changed
if: inputs.chartChangesDetected == 'true'
run: |
EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .ci/ct/ct-lint.yaml)
CHARTS=$(ct list-changed --config .ci/ct/ct-lint.yaml)
CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]')
OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded')
echo ::set-output name=charts::${OUTPUT_JSON}
if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then
echo "::set-output name=detected::true"
fi
- name: Run chart-testing (lint)
id: lint
if: steps.list-changed.outputs.detected == 'true'
run: ct lint --config .ci/ct/ct-lint.yaml

60
.github/workflows/pr-metadata.yaml vendored Normal file
View file

@ -0,0 +1,60 @@
name: "Pull Request: Get metadata"
on:
workflow_call:
outputs:
isRenovatePR:
description: "Is the PR coming from Renovate?"
value: ${{ jobs.pr-metadata.outputs.isRenovatePR }}
isFork:
description: "Is the PR coming from a forked repo?"
value: ${{ jobs.pr-metadata.outputs.isFork }}
addedOrModified:
description: "Does the PR contain any changes?"
value: ${{ jobs.pr-changes.outputs.addedOrModified }}
addedOrModifiedFiles:
description: "A list of the files changed in this PR"
value: ${{ jobs.pr-changes.outputs.addedOrModifiedFiles }}
addedOrModifiedCharts:
description: "A list of the charts changed in this PR"
value: ${{ jobs.pr-changes.outputs.addedOrModifiedCharts }}
jobs:
pr-metadata:
name: Collect PR metadata
runs-on: ubuntu-latest
outputs:
isRenovatePR: ${{ startsWith(steps.branch-name.outputs.current_branch, 'renovate/') }}
isFork: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.4
- name: Save PR data to file
env:
PR_NUMBER: ${{ github.event.number }}
run: |
echo $PR_NUMBER > pr_number.txt
- name: Store pr data in artifact
uses: actions/upload-artifact@v3
with:
name: pr_metadata
path: ./pr_number.txt
retention-days: 5
pr-changes:
name: Collect PR changes
runs-on: ubuntu-latest
outputs:
addedOrModified: ${{ steps.collect-changes.outputs.changesDetected }}
addedOrModifiedFiles: ${{ steps.collect-changes.outputs.addedOrModifiedFiles }}
addedOrModifiedCharts: ${{ steps.collect-changes.outputs.addedOrModifiedCharts }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Collect changes
id: collect-changes
uses: ./.github/actions/collect-changes

55
.github/workflows/pr-validate.yaml vendored Normal file
View file

@ -0,0 +1,55 @@
name: "Pull Request: Validate"
on:
pull_request:
branches:
- main
- development
types:
- opened
- edited
- reopened
- ready_for_review
- synchronize
concurrency:
group: ${{ github.head_ref }}-pr-validate
cancel-in-progress: true
jobs:
pr-metadata:
uses: bjw-s/charts/.github/workflows/pr-metadata.yaml@main
pre-commit-check:
uses: bjw-s/charts/.github/workflows/pre-commit-check.yaml@main
needs:
- pr-metadata
with:
modifiedFiles: ${{ needs.pr-metadata.outputs.addedOrModifiedFiles }}
# charts-changelog:
# uses: bjw-s/charts/.github/workflows/charts-changelog.yaml@main
# needs:
# - pr-metadata
# - pre-commit-check
# with:
# isRenovatePR: ${{ needs.pr-metadata.outputs.isRenovatePR }}
# modifiedCharts: ${{ needs.pr-metadata.outputs.addedOrModifiedCharts }}
charts-lint:
uses: bjw-s/charts/.github/workflows/charts-lint.yaml@main
needs:
- pr-metadata
- charts-changelog
with:
checkoutCommit: ${{ needs.charts-changelog.outputs.commitHash }}
chartChangesDetected: ${{ needs.pr-metadata.outputs.addedOrModified }}
# charts-test:
# uses: bjw-s/charts/.github/workflows/charts-test.yaml@main
# needs:
# - pr-metadata
# - charts-changelog
# with:
# checkoutCommit: ${{ needs.charts-changelog.outputs.commitHash }}
# chartChangesDetected: ${{ needs.pr-metadata.outputs.addedOrModified }}