@@ -2,7 +2,7 @@ name: Build and Release
22
33on :
44 push :
5- branches : [main]
5+ branches : [main, dev ]
66 tags :
77 - " v*"
88 pull_request :
1818 run : |
1919 apk add --no-cache git make gcc musl-dev
2020
21- - uses : actions/checkout@v3
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
2225
2326 - name : Configure Git safe directory
2427 run : |
@@ -37,48 +40,60 @@ jobs:
3740 if : startsWith(github.ref, 'refs/tags/v')
3841 runs-on : ubuntu-latest
3942 steps :
40- - uses : actions/checkout@v3
43+ - name : Checkout code
44+ uses : actions/checkout@v4
45+ with :
46+ fetch-depth : 0
4147
4248 - name : Set up Docker Buildx
43- uses : docker/setup-buildx-action@v2
49+ uses : docker/setup-buildx-action@v3
4450
4551 - name : Login to DockerHub
46- uses : docker/login-action@v2
52+ uses : docker/login-action@v3
4753 with :
4854 username : ${{ secrets.DOCKERHUB_USERNAME }}
4955 password : ${{ secrets.DOCKERHUB_TOKEN }}
5056
57+ - name : Check Docker login status
58+ run : |
59+ echo "Checking Docker Hub login status..."
60+ docker info
61+ echo "DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}"
62+ echo "DOCKERHUB_TOKEN is set: ${{ secrets.DOCKERHUB_TOKEN != '' }}"
63+
64+ # 创建仓库(如果不存在)
65+ echo "Creating repositories if they don't exist..."
66+ docker buildx create --use
67+ docker buildx build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-dispatcher:latest -f ./docker/dispatcher/Dockerfile . --push || echo "Repository may already exist"
68+ docker buildx build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-validator:latest -f ./docker/validator/Dockerfile . --push || echo "Repository may already exist"
69+
5170 - name : Extract metadata for Docker
5271 id : meta
53- uses : docker/metadata-action@v4
72+ uses : docker/metadata-action@v5
5473 with :
55- images : hetuproject /checkpoint-dispatcher,hetuproject /checkpoint-validator
74+ images : ${{ secrets.DOCKERHUB_USERNAME }} /checkpoint-dispatcher,${{ secrets.DOCKERHUB_USERNAME }} /checkpoint-validator
5675 tags : |
5776 type=semver,pattern={{version}}
5877 type=semver,pattern={{major}}.{{minor}}
59- type=sha
78+ latest
6079
6180 - name : Build and push dispatcher image
62- uses : docker/build-push-action@v4
81+ uses : docker/build-push-action@v5
6382 with :
6483 context : .
6584 file : ./docker/dispatcher/Dockerfile
6685 push : true
67- tags : hetuproject/checkpoint-dispatcher:${{ steps.meta.outputs.version }},hetuproject/checkpoint-dispatcher:latest
68- cache-from : type=registry,ref=hetuproject/checkpoint-dispatcher:buildcache
69- cache-to : type=registry,ref=hetuproject/checkpoint-dispatcher:buildcache,mode=max
70- platforms : linux/amd64,linux/arm64
86+ tags : ${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-dispatcher:latest,${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-dispatcher:${{ github.ref_name }}
87+ platforms : linux/amd64
7188
7289 - name : Build and push validator image
73- uses : docker/build-push-action@v4
90+ uses : docker/build-push-action@v5
7491 with :
7592 context : .
7693 file : ./docker/validator/Dockerfile
7794 push : true
78- tags : hetuproject/checkpoint-validator:${{ steps.meta.outputs.version }},hetuproject/checkpoint-validator:latest
79- cache-from : type=registry,ref=hetuproject/checkpoint-validator:buildcache
80- cache-to : type=registry,ref=hetuproject/checkpoint-validator:buildcache,mode=max
81- platforms : linux/amd64,linux/arm64
95+ tags : ${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-validator:latest,${{ secrets.DOCKERHUB_USERNAME }}/checkpoint-validator:${{ github.ref_name }}
96+ platforms : linux/amd64
8297
8398 release :
8499 needs : build
@@ -91,7 +106,10 @@ jobs:
91106 run : |
92107 apk add --no-cache git make gcc musl-dev zip tar
93108
94- - uses : actions/checkout@v3
109+ - name : Checkout code
110+ uses : actions/checkout@v4
111+ with :
112+ fetch-depth : 0
95113
96114 - name : Configure Git safe directory
97115 run : |
@@ -100,47 +118,40 @@ jobs:
100118 - name : Build binaries
101119 run : |
102120 # Build for multiple platforms
103- mkdir -p build/linux/amd64 build/linux/arm64 build/ darwin/amd64 build/windows/amd64
121+ mkdir -p build/linux/amd64 build/darwin/amd64 build/windows/amd64
104122
105123 # Linux amd64
106124 CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o build/linux/amd64/dispatcher ./cmd/dispatcher
107125 CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o build/linux/amd64/validator ./cmd/validator
108126
109- # Linux arm64
110- CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o build/linux/arm64/dispatcher ./cmd/dispatcher
111- CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o build/linux/arm64/validator ./cmd/validator
112-
113127 # macOS (Darwin)
114- CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/dispatcher ./cmd/dispatcher
115- CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/validator ./cmd/validator
128+ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/dispatcher ./cmd/dispatcher
129+ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/validator ./cmd/validator
116130
117131 # Windows
118- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/dispatcher.exe ./cmd/dispatcher
119- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/validator.exe ./cmd/validator
132+ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/dispatcher.exe ./cmd/dispatcher
133+ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/validator.exe ./cmd/validator
120134
121135 - name : Create release archives
122136 run : |
123137 mkdir -p release
124138 cd build/linux/amd64 && tar -czvf ../../../release/checkpoint-linux-amd64.tar.gz * && cd -
125- cd build/linux/arm64 && tar -czvf ../../../release/checkpoint-linux-arm64.tar.gz * && cd -
126139 cd build/darwin/amd64 && tar -czvf ../../../release/checkpoint-darwin-amd64.tar.gz * && cd -
127140 cd build/windows/amd64 && zip -r ../../../release/checkpoint-windows-amd64.zip * && cd -
128141
129- - name : Upload artifacts
130- uses : actions/upload-artifact@v3
131- with :
132- name : release-binaries
133- path : release/
142+ # use GitHub CLI to replace actions/upload-artifact
143+ - name : Install GitHub CLI
144+ run : |
145+ apk add --no-cache github-cli
134146
135- - name : Create Release
136- uses : softprops/action-gh-release@v1
137- with :
138- files : |
139- release/checkpoint-linux-amd64.tar.gz
140- release/checkpoint-linux-arm64.tar.gz
141- release/checkpoint-darwin-amd64.tar.gz
142- release/checkpoint-windows-amd64.zip
143- draft : false
144- prerelease : false
147+ - name : Create GitHub Release
145148 env :
146149 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
150+ run : |
151+ VERSION=${GITHUB_REF#refs/tags/}
152+ gh release create $VERSION \
153+ --title "Release $VERSION" \
154+ --notes "Release $VERSION" \
155+ release/checkpoint-linux-amd64.tar.gz \
156+ release/checkpoint-darwin-amd64.tar.gz \
157+ release/checkpoint-windows-amd64.zip
0 commit comments