@@ -2,6 +2,10 @@ name: CI Workflow
22
33on : [pull_request, workflow_dispatch]
44
5+ permissions :
6+ pull-requests : write # required to add comments to the PR
7+ contents : read
8+
59jobs :
610 main :
711 name : CI
@@ -13,10 +17,12 @@ jobs:
1317 steps :
1418 - name : Checkout
1519 uses : actions/checkout@v4
20+
1621 - name : Install Go ${{ matrix.go-version }}
1722 uses : actions/setup-go@v5
1823 with :
1924 go-version : ${{ matrix.go-version }}
25+
2026 - name : Test
2127 run : make test
2228
@@ -29,13 +35,121 @@ jobs:
2935 steps :
3036 - name : Checkout
3137 uses : actions/checkout@v4
38+
3239 - name : Install Go
3340 uses : actions/setup-go@v5
3441 with :
3542 go-version : 1.25
43+
3644 - name : Install project tools and dependencies
3745 run : make project-tools
46+
3847 - name : Lint
3948 run : |
4049 make lint
4150 scripts/check-sync-tidy.sh
51+
52+ detect-sdk-modules :
53+ name : Detect changed SDK modules
54+ runs-on : ubuntu-latest
55+ outputs :
56+ matrix : ${{ steps.set-matrix.outputs.matrix }}
57+ steps :
58+ - name : Checkout code
59+ uses : actions/checkout@v4
60+ with :
61+ fetch-depth : 0
62+
63+ - name : Find changed Go modules
64+ id : set-matrix
65+ run : |
66+ MODULES=()
67+
68+ # Find all directories containing a go.mod file
69+ for mod in $(find . -name "go.mod" | sort); do
70+ dir=$(dirname "$mod")
71+
72+ # Clean up the path (e.g., convert "./module" to "module", and "." remains ".")
73+ dir=${dir#./}
74+
75+ # Check if there are differences in this directory compared to the base branch
76+ if ! git diff --quiet origin/${{ github.base_ref }} HEAD -- "$dir"; then
77+ MODULES+=("\"$dir\"")
78+ fi
79+ done
80+
81+ # Format as a JSON array for the matrix job
82+ JSON="[$(IFS=,; echo "${MODULES[*]}")]"
83+ echo "Changed modules: $JSON"
84+ echo "matrix=$JSON" >> $GITHUB_OUTPUT
85+
86+ gorelease-check :
87+ name : Run gorelease check
88+ needs : [ "detect-sdk-modules" ]
89+ # Skip the entire job if the JSON array is empty (no modules changed)
90+ if : ${{ needs.detect-sdk-modules.outputs.matrix != '[]' && needs.detect-sdk-modules.outputs.matrix != '' }}
91+ runs-on : ubuntu-latest
92+ strategy :
93+ fail-fast : false
94+ matrix :
95+ module : ${{ fromJSON(needs.detect-sdk-modules.outputs.matrix) }}
96+
97+ steps :
98+ - name : Checkout code
99+ uses : actions/checkout@v4
100+
101+ - name : Install Go
102+ uses : actions/setup-go@v5
103+ with :
104+ go-version : 1.25
105+
106+ - name : Install gorelease
107+ run : go install golang.org/x/exp/cmd/gorelease@latest
108+
109+ - name : Run gorelease
110+ id : gorelease
111+ working-directory : ${{ matrix.module }}
112+ run : |
113+ # Disable "exit on error" temporarily so we can capture the output
114+ # even if gorelease finds backwards incompatibilities (which causes exit code 1)
115+ set +e
116+ OUTPUT=$(gorelease 2>&1)
117+ EXIT_CODE=$?
118+ set -e
119+
120+ # Securely write multi-line output to GITHUB_OUTPUT using EOF marker
121+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
122+ echo "report<<$EOF" >> $GITHUB_OUTPUT
123+ echo "$OUTPUT" >> $GITHUB_OUTPUT
124+ echo "$EOF" >> $GITHUB_OUTPUT
125+
126+ # Save the exit code to evaluate later
127+ echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
128+
129+ - name : Comment PR
130+ uses : actions/github-script@v7
131+ env :
132+ REPORT : ${{ steps.gorelease.outputs.report }}
133+ MODULE : ${{ matrix.module }}
134+ with :
135+ github-token : ${{ secrets.GITHUB_TOKEN }}
136+ script : |
137+ const report = process.env.REPORT || "No output generated.";
138+ const module = process.env.MODULE;
139+
140+ // Format the comment
141+ const body = `### \`gorelease\` report for \`${module}\`\n\n\`\`\`text\n${report}\n\`\`\``;
142+
143+ // Post the comment to the PR
144+ github.rest.issues.createComment({
145+ issue_number: context.issue.number,
146+ owner: context.repo.owner,
147+ repo: context.repo.repo,
148+ body: body
149+ })
150+
151+ - name : Fail job if gorelease failed
152+ if : ${{ steps.gorelease.outputs.exit_code != '0' }}
153+ run : |
154+ echo "gorelease exited with code ${{ steps.gorelease.outputs.exit_code }}"
155+ exit ${{ steps.gorelease.outputs.exit_code }}
0 commit comments