-
Notifications
You must be signed in to change notification settings - Fork 22
145 lines (129 loc) · 5.43 KB
/
Copy path000-flow-changeset-check.yaml
File metadata and controls
145 lines (129 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: "000: [FLOW] Changeset Check"
on:
pull_request:
branches:
- develop
- development
types:
- opened
- synchronize
- reopened
- labeled # checks for bypass labels (no-changeset, docs-only, hotfix, chore)
- unlabeled
defaults:
run:
shell: bash
permissions:
contents: read
pull-requests: read
jobs:
check-changeset:
name: Validate Changeset Required
runs-on: token-studio-linux-medium
timeout-minutes: 5
steps:
- name: Harden Runner
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
# Ensure we have the head branch for comparison
ref: ${{ github.head_ref }}
- name: Fetch base branch
run: |
echo "Base branch: ${{ github.base_ref }}"
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
git branch -a
- name: Setup NodeJS Environment
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: .nvmrc
- name: Check for bypass labels
id: bypass
env:
GH_TOKEN: ${{ github.token }}
run: |
LABELS=$(gh pr view ${{ github.event.number }} --json labels --jq '.labels[].name' || echo "")
if echo "${LABELS}" | grep -E "(no-changeset|docs-only|hotfix|chore)" > /dev/null; then
echo "bypass=true" >> "${GITHUB_OUTPUT}"
echo "✅ Found bypass label. Skipping changeset check."
else
echo "bypass=false" >> "${GITHUB_OUTPUT}"
echo "🔍 No bypass labels found. Changeset check required."
fi
- name: Install dependencies
if: ${{ steps.bypass.outputs.bypass == 'false' }}
run: npm ci
- name: Check changeset status
if: ${{ steps.bypass.outputs.bypass == 'false' }}
env:
BASE_BRANCH: ${{ github.base_ref }}
run: |
echo "🔍 Checking for NEW changesets in this PR..."
echo "Comparing HEAD against base branch: ${BASE_BRANCH}"
NEW_CHANGESETS=$(git diff "${BASE_BRANCH}...HEAD" --name-only --diff-filter=A | grep "^\.changeset/.*\.md$" | grep -v "README.md" || true)
NEW_CHANGESET_COUNT=$(echo "${NEW_CHANGESETS}" | grep -c "\.md$" || true)
echo "Files changed in PR:"
git diff "${BASE_BRANCH}...HEAD" --name-only --diff-filter=A | head -10
echo ""
echo "NEW changeset files in this PR: ${NEW_CHANGESET_COUNT}"
if [[ -n "${NEW_CHANGESETS}" ]]; then
echo "Found NEW changesets:"
echo "${NEW_CHANGESETS}"
fi
if [[ "${NEW_CHANGESET_COUNT}" -gt 0 ]]; then
echo "✅ Changeset validation passed - found NEW changeset files in PR"
else
echo ""
echo "❌ NEW CHANGESET REQUIRED"
echo ""
echo "This PR requires a NEW changeset to document the changes."
echo "We found no new .changeset/*.md files introduced by this PR."
echo ""
echo "To create a changeset:"
echo "1. Run: npm run changeset"
echo "2. Select the packages that changed"
echo "3. Choose the change type (patch/minor/major)"
echo "4. Write a description of your changes"
echo "5. Commit the generated .changeset/*.md file"
echo ""
echo "To bypass this check (for docs/chore changes only):"
echo "Add one of these labels to the PR:"
echo "- no-changeset: For pure documentation or config changes"
echo "- docs-only: For documentation-only changes"
echo "- chore: For build system or dependency updates"
echo "- hotfix: For emergency fixes"
echo ""
echo "More info: https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md"
exit 1
fi
- name: Validate changeset contents
if: ${{ steps.bypass.outputs.bypass == 'false' }}
run: |
echo "🔍 Validating that all pending changesets reference known workspace packages..."
if ! npx changeset status; then
echo ""
echo "❌ CHANGESET CONTENT VALIDATION FAILED"
echo ""
echo "One or more .changeset/*.md files reference a package name that does not"
echo "exist in this workspace (see .changeset/config.json 'fixed' groups for the"
echo "authoritative names). Open the failing changeset and replace the package"
echo "name with the correct workspace name, e.g.:"
echo ""
echo " @asset-tokenization-studio/ats-contracts -> @hashgraph/asset-tokenization-contracts"
echo ""
echo "Then re-run \`npx changeset status\` locally to confirm before pushing."
exit 1
fi
echo "✅ All pending changesets reference valid workspace packages"
- name: Success summary
if: ${{ always() }}
run: |
if [[ "${{ steps.bypass.outputs.bypass }}" == "true" ]]; then
echo "✅ Changeset check bypassed due to label"
else
echo "✅ Changeset validation completed successfully"
fi