Composite action versioning #8
Workflow file for this run
This file contains hidden or 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: Validate PR Version Labels | |
| on: | |
| pull_request: | |
| branches: [main] | |
| types: | |
| - opened | |
| - synchronize | |
| - edited | |
| - labeled # important to catch version label additions | |
| - unlabeled | |
| - reopened | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| validate-version-labels: | |
| name: Validate PR Version Labels | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Get all labels on the PR | |
| id: get_labels | |
| run: | | |
| SUMMARY_FILE="$GITHUB_STEP_SUMMARY" | |
| echo "## PR Labels" >> "$SUMMARY_FILE" | |
| all_labels=$(jq -r '.pull_request.labels[].name' < "$GITHUB_EVENT_PATH" 2>/dev/null || true) | |
| if [ -z "$all_labels" ]; then | |
| echo "- (none)" >> "$SUMMARY_FILE" | |
| echo "::error title=No Labels::No Labels were found on this PR. A version label is required." | |
| exit 1 | |
| else | |
| while IFS= read -r lbl; do | |
| [ -z "$lbl" ] && continue | |
| echo "- \`$lbl\`" >> "$SUMMARY_FILE" | |
| done <<< "$all_labels" | |
| fi | |
| # Save labels for later steps | |
| { | |
| echo "all_labels<<EOF" | |
| echo "$all_labels" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Filter Version Labels | |
| id: filter_labels | |
| run: | | |
| all_labels="${{ steps.get_labels.outputs.all_labels }}" | |
| version_labels=$(echo "$all_labels" | grep -E '^version:(.+):v[0-9]+\.[0-9]+\.[0-9]+$|^version:untracked$' || true) | |
| if [ -z "$version_labels" ]; then | |
| echo "::error title=No Version Labels::No version labels found on this PR. A version label is required." | |
| exit 1 | |
| fi | |
| echo "$version_labels" >> "$GITHUB_OUTPUT" | |
| - name: Untrack Label Check | |
| id: untracked_check | |
| run: | | |
| version_labels="${{ steps.filter_labels.outputs.version_labels }}" | |
| //TODO check for version:untracked label | |
| // error if other version labels are present along with it | |
| if echo "$version_labels" | grep -q '^version:untracked$' &&; then | |
| if [ "$(echo "$version_labels" | wc -l)" -gt 1 ]; then | |
| echo "::error title=Conflicting Version Labels::The label 'version:untracked' cannot be used with other version labels." | |
| exit 1 | |
| fi | |
| fi | |
| - name: Outcome | |
| if: ${{ always() }} | |
| env: | |
| NO_LABELS: ${{ steps.get_labels.outcome == 'failure' }} | |
| NO_VERSION_LABELS: ${{ steps.filter_labels.outcome == 'failure' }} | |
| CONFLICTING_LABELS: ${{ steps.untracked_check.outcome == 'failure' }} | |
| run: | | |
| SUMMARY_FILE="$GITHUB_STEP_SUMMARY" | |
| echo "## Validation Outcome" >> "$SUMMARY_FILE" | |
| if [ "${{ env.NO_LABELS }}" = "true" ]; then | |
| echo "❌ No labels found on the PR. Add at least one version label." >> "$SUMMARY_FILE" | |
| fi | |
| if [ "${{ env.NO_VERSION_LABELS }}" = "true" ]; then | |
| echo "❌ No version labels found on the PR. Add at least one version label." >> "$SUMMARY_FILE" | |
| fi | |
| if [ "${{ env.CONFLICTING_LABELS }}" = "true" ]; then | |
| echo "❌ Conflicting version labels found. \`version:untracked\` cannot be used with other version labels)." >> "$SUMMARY_FILE" | |
| fi | |
| echo "> PR must include a version label." >> "$SUMMARY_FILE" | |
| echo "> See Version Labeling Policy in VERSIONING.md for details." >> "$SUMMARY_FILE" | |