-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): validate and label pull requests separately (#643)
- Loading branch information
Showing
5 changed files
with
74 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
[[ "$RUNNER_DEBUG" == 1 ]] && set -x | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
: "${PR_TITLE:?Environment variable must be set}" | ||
|
||
changed="${CHANGED_CHART?Environment variable must be set}" | ||
|
||
if ! cog verify "$PR_TITLE"; then | ||
echo "PR title must be a conventional commit message" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -n "$changed" ]] && ! cog verify "$PR_TITLE" 2>&1 | grep -Eq "^\s+Scope: $changed(/.+|)\$"; then | ||
echo "PR title must have scope '$changed/\$subscope'" >&2 | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,6 @@ name: Get single changed chart in last commit | |
|
||
on: | ||
workflow_call: | ||
inputs: | ||
chart: | ||
type: string | ||
required: false | ||
description: The name of the chart to run against | ||
outputs: | ||
chart: | ||
description: The name of the changed cart in the last commit | ||
|
@@ -16,7 +11,7 @@ jobs: | |
getChangedChart: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
chart: ${{ steps.getChartName.outputs.chart }} | ||
chart: ${{ steps.getChangedChart.outputs.chart }} | ||
env: | ||
CT_TARGET_BRANCH: ${{ github.event.repository.default_branch }} | ||
steps: | ||
|
@@ -25,26 +20,24 @@ jobs: | |
fetch-depth: 0 | ||
|
||
- uses: helm/[email protected] | ||
if: ${{ !inputs.chart }} | ||
|
||
- id: getChangedChart | ||
if: ${{ !inputs.chart }} | ||
name: Get changed chart in this commit | ||
run: | | ||
set -x | ||
set -o pipefail | ||
( | ||
echo -n chart= | ||
ct list-changed --since "HEAD~" | cut -d / -f 2 | ||
) | tee "$GITHUB_OUTPUT" | ||
- id: getChartName | ||
name: Get name for changed chart | ||
run: | | ||
set -x | ||
set -o pipefail | ||
chart="${{ inputs.chart }}" | ||
chart="${chart:-${{ steps.getChangedChart.outputs.chart }}}" | ||
chart=${chart:?chart variable is empty} | ||
( | ||
echo "chart=${chart}" | ||
) | tee "$GITHUB_OUTPUT" | ||
changed="$(ct list-changed --since "HEAD~" | cut -d / -f 2)" | ||
if [[ -z "$changed" ]]; then | ||
echo chart= | tee "$GITHUB_OUTPUT" | ||
exit 0 | ||
fi | ||
num_changed=$(wc -l <<<"$changed") | ||
if ((num_changed > 1)); then | ||
echo "This PR has changes to multiple charts. Please create individual PRs per chart." >&2 | ||
exit 1 | ||
fi | ||
echo chart="$changed" | tee "$GITHUB_OUTPUT" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Label Chart Pull Request | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- charts/** | ||
types: | ||
- opened | ||
- edited | ||
- reopened | ||
- synchronize | ||
|
||
jobs: | ||
getChangedChart: | ||
uses: ./.github/workflows/get-changed-chart.yaml | ||
labelPullRequest: | ||
name: Validate and label PR | ||
runs-on: ubuntu-latest | ||
needs: getChangedChart | ||
steps: | ||
- env: | ||
PR_TITLE: ${{ github.event.pull_request.title }} | ||
GITHUB_TOKEN: ${{ github.token }} | ||
ISSUE_NUMBER: ${{ github.event.number }} | ||
CHANGED_CHART: ${{ needs.getChangedChart.outputs.chart }} | ||
run: | | ||
curl --silent --fail-with-body \ | ||
-X POST \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H "Authorization: token ${GITHUB_TOKEN}" \ | ||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}/labels" \ | ||
-d '{"labels":["'"$CHANGED_CHART"'"]}' |
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