Skip to content

Commit fa080c5

Browse files
committed
update
1 parent 46f4e8c commit fa080c5

File tree

1 file changed

+50
-58
lines changed

1 file changed

+50
-58
lines changed

.github/workflows/build_and_unit_test.yml

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ on:
88
types: [ opened, synchronize, reopened, edited, ready_for_review ]
99
workflow_dispatch:
1010

11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
1119
env:
1220
GO_VERSION: '1.21'
21+
GOPATH: ${{ github.workspace }}/.go
22+
GOBIN: ${{ github.workspace }}/.go/bin
1323

1424
jobs:
1525
# Code quality checks
@@ -27,73 +37,65 @@ jobs:
2737
go-version: ${{ env.GO_VERSION }}
2838
cache: true
2939

40+
- name: Setup GOPATH/PATH
41+
run: |
42+
echo "GOPATH=${GOPATH}" >> "$GITHUB_ENV"
43+
echo "${GOBIN}" >> "$GITHUB_PATH"
44+
3045
- name: Install dependencies
3146
run: make depend
3247

33-
- name: Code formatting check
48+
- name: Formatting check (read-only)
3449
run: |
35-
make format
36-
if [ -n "$(git diff --name-only)" ]; then
37-
echo "Code is not properly formatted. Please run 'make format'"
38-
git diff
50+
go install golang.org/x/tools/cmd/goimports@latest
51+
CHANGED=$(goimports -l $(git ls-files '*.go'))
52+
if [ -n "$CHANGED" ]; then
53+
echo "The following files need formatting:"
54+
echo "$CHANGED"
55+
echo "Please run: make format"
3956
exit 1
4057
fi
4158
42-
- name: Lint code
43-
run: make lint
59+
- name: GolangCI-Lint
60+
uses: golangci/golangci-lint-action@v4
61+
with:
62+
version: v1.56.2
63+
args: --tests=false
64+
only-new-issues: true
4465

45-
# Build and unit test
66+
# Build and unit tests with GPDB version matrix
4667
build_and_unit_test:
4768
needs: code_quality
4869
runs-on: ubuntu-latest
49-
70+
5071
steps:
5172
- name: Checkout code
5273
uses: actions/checkout@v4
5374
with:
5475
fetch-depth: 0
55-
path: go/src/github.com/apache/cloudberry-backup
5676

5777
- name: Set up Go
5878
uses: actions/setup-go@v5
5979
with:
6080
go-version: ${{ env.GO_VERSION }}
6181
cache: true
6282

63-
- name: Set Environment
83+
- name: Setup GOPATH/PATH
6484
run: |
65-
echo "GOPATH=/home/runner/work/gpbackup/gpbackup/go" >> $GITHUB_ENV
66-
echo "/home/runner/work/gpbackup/gpbackup/go/bin" >> $GITHUB_PATH
67-
68-
- name: Cache Go modules
69-
uses: actions/cache@v4
70-
with:
71-
path: |
72-
~/.cache/go-build
73-
~/go/pkg/mod
74-
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
75-
restore-keys: |
76-
${{ runner.os }}-go-${{ env.GO_VERSION }}-
77-
${{ runner.os }}-go-
85+
echo "GOPATH=${GOPATH}" >> "$GITHUB_ENV"
86+
echo "${GOBIN}" >> "$GITHUB_PATH"
87+
echo "GOFLAGS=-trimpath" >> "$GITHUB_ENV"
7888
7989
- name: Install dependencies
80-
run: |
81-
cd ${GOPATH}/src/github.com/apache/cloudberry-backup
82-
make depend
90+
run: make depend
8391

8492
- name: Build binaries
85-
run: |
86-
cd ${GOPATH}/src/github.com/apache/cloudberry-backup
87-
make build
93+
run: make build
8894

8995
- name: Run unit tests with coverage
90-
run: |
91-
cd ${GOPATH}/src/github.com/apache/cloudberry-backup
92-
make unit_all_gpdb_versions
9396

94-
- name: Generate coverage report
9597
run: |
96-
cd ${GOPATH}/src/github.com/apache/cloudberry-backup
98+
make unit
9799
make coverage
98100
99101
- name: Upload coverage to Codecov
@@ -107,11 +109,11 @@ jobs:
107109
- name: Upload build artifacts
108110
uses: actions/upload-artifact@v4
109111
with:
110-
name: binaries-ubuntu-latest-go${{ env.GO_VERSION }}
112+
name: binaries-ubuntu-latest-go${{ env.GO_VERSION }}-${{ github.sha }}
111113
path: |
112-
/home/runner/work/gpbackup/gpbackup/go/bin/gpbackup
113-
/home/runner/work/gpbackup/gpbackup/go/bin/gprestore
114-
/home/runner/work/gpbackup/gpbackup/go/bin/gpbackup_helper
114+
${{ env.GOBIN }}/gpbackup
115+
${{ env.GOBIN }}/gprestore
116+
${{ env.GOBIN }}/gpbackup_helper
115117
retention-days: 7
116118

117119
# Integration test with Apache Cloudberry
@@ -150,23 +152,27 @@ jobs:
150152
repository: apache/cloudberry
151153
ref: main
152154
fetch-depth: 1
155+
persist-credentials: false
153156
path: cloudberry
154157

155158
- name: Checkout backup utility code
156159
uses: actions/checkout@v4
157160
with:
158161
fetch-depth: 1
162+
persist-credentials: false
159163
path: cloudberry-backup
160164

161165
- name: Set up Go in container
162166
run: |
163-
# Install Go 1.21 in the container
167+
# Install Go 1.21 in the container (retain original approach)
164168
cd /tmp
165169
wget -q https://go.dev/dl/go${{ env.GO_VERSION }}.linux-amd64.tar.gz
166170
tar -C /usr/local -xzf go${{ env.GO_VERSION }}.linux-amd64.tar.gz
167171
echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile
168172
echo 'export GOPATH=/home/gpadmin/go' >> /etc/profile
169173
echo 'export PATH=$PATH:/home/gpadmin/go/bin' >> /etc/profile
174+
echo "/home/gpadmin/go/bin" >> "$GITHUB_PATH"
175+
echo "GOPATH=/home/gpadmin/go" >> "$GITHUB_ENV"
170176
171177
- name: Configure Apache Cloudberry
172178
env:
@@ -177,7 +183,6 @@ jobs:
177183
set -eo pipefail
178184
chown -R gpadmin:gpadmin ${SRC_DIR}
179185
180-
# Run configure script as gpadmin user
181186
su - gpadmin -c "
182187
cd ${SRC_DIR}
183188
export SRC_DIR=${SRC_DIR}
@@ -192,8 +197,6 @@ jobs:
192197
SRC_DIR: ${{ github.workspace }}/cloudberry
193198
run: |
194199
set -eo pipefail
195-
196-
# Run build script as gpadmin user
197200
su - gpadmin -c "
198201
cd ${SRC_DIR}
199202
export SRC_DIR=${SRC_DIR}
@@ -207,8 +210,6 @@ jobs:
207210
NUM_PRIMARY_MIRROR_PAIRS: 1
208211
run: |
209212
set -eo pipefail
210-
211-
# Create demo cluster as gpadmin user
212213
su - gpadmin -c "
213214
cd ${SRC_DIR}
214215
export SRC_DIR=${SRC_DIR}
@@ -223,10 +224,7 @@ jobs:
223224
source /usr/local/cloudberry-db/cloudberry-env.sh
224225
source ${GITHUB_WORKSPACE}/cloudberry/gpAux/gpdemo/gpdemo-env.sh
225226
226-
# Verify cluster is running
227227
gpstate -s
228-
229-
# Test basic connectivity
230228
psql -d postgres -c 'SELECT version();'
231229
psql -d postgres -c 'SELECT * FROM gp_segment_configuration;'
232230
"
@@ -240,30 +238,24 @@ jobs:
240238
export GOPATH=${GOPATH}
241239
export PATH=\$PATH:\$GOPATH/bin
242240
243-
# Source Cloudberry environment
244241
source /usr/local/cloudberry-db/cloudberry-env.sh
245242
source ${GITHUB_WORKSPACE}/cloudberry/gpAux/gpdemo/gpdemo-env.sh
246243
247244
cd ${GITHUB_WORKSPACE}/cloudberry-backup
248245
249-
# Set up GOPATH structure for backup utility
250246
mkdir -p \$GOPATH/src/github.com/apache
251247
ln -sf ${GITHUB_WORKSPACE}/cloudberry-backup \$GOPATH/src/github.com/apache/cloudberry-backup
252248
253249
cd \$GOPATH/src/github.com/apache/cloudberry-backup
254250
255-
# Install dependencies
256251
make depend
257-
258-
# Build the backup utilities
259252
make build
260253
261-
# Run unit tests (these don't require database connection)
262-
make unit_all_gpdb_versions
254+
# Run unit tests (no DB connection required)
255+
make unit
263256
264-
# Run integration tests with the demo cluster
265257
echo 'Running integration tests with Cloudberry cluster...'
266-
make integration || echo 'Integration tests completed with some failures (expected in CI)'
258+
make integration || echo 'Integration tests completed with some failures (soft fail in CI)'
267259
"
268260
269261
- name: Upload integration test logs
@@ -274,4 +266,4 @@ jobs:
274266
path: |
275267
build-logs/
276268
cloudberry/build-logs/
277-
retention-days: 7
269+
retention-days: 7

0 commit comments

Comments
 (0)