Skip to content

Commit f1a2711

Browse files
authored
Use gh cli to download releases (microsoft#1792)
Use official github cli tool to download releases, instead of manually creating URLs. Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 933d9b1 commit f1a2711

3 files changed

Lines changed: 64 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99

1010
jobs:
1111
lint:
12-
runs-on: "windows-2019"
12+
runs-on: "windows-2022"
1313
strategy:
1414
fail-fast: false
1515
matrix:
@@ -48,7 +48,12 @@ jobs:
4848
GOOS: ${{ matrix.goos }}
4949

5050
protos:
51-
runs-on: "windows-2019"
51+
runs-on: "windows-2022"
52+
53+
env:
54+
# translating from github.com/Microsoft/hcsshim/<path> (via `go list`) to <path> is easier if hcsshim is in GOPATH/src
55+
GOPATH: '${{ github.workspace }}\go'
56+
5257
steps:
5358
- uses: actions/setup-go@v4
5459
with:
@@ -72,55 +77,78 @@ jobs:
7277
"containerd_ref=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7378
working-directory: go/src/github.com/Microsoft/hcsshim
7479

75-
# Install protoc-gen-gogoctrd in D:\bin
7680
- uses: actions/checkout@v3
7781
with:
7882
repository: containerd/containerd
7983
path: "containerd"
8084
ref: "${{ env.containerd_ref }}"
8185
name: Checkout containerd
8286

83-
- name: Install protoc-gen-gogoctrd
87+
- name: Install protobuild and protoc-gen-gogoctrd
8488
shell: powershell
8589
run: |
90+
# not actually GOBIN
91+
$goBin = Join-Path (go env GOPATH) 'bin'
92+
mkdir -f $goBin
93+
$goBin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
94+
95+
go install github.com/containerd/[email protected]
96+
8697
cd containerd
87-
go build ./cmd/protoc-gen-gogoctrd
88-
mkdir D:\bin
89-
mv protoc-gen-gogoctrd.exe D:\bin
98+
go build -o $goBin ./cmd/protoc-gen-gogoctrd
9099
91-
# Install protoc in D:\bin
92100
- name: Install protoc
93101
shell: powershell
94102
run: |
95-
Invoke-WebRequest -OutFile protoc.zip -Uri https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-win32.zip
96-
Expand-Archive -Path protoc.zip -DestinationPath .
97-
mv include go/src/github.com/Microsoft/hcsshim/protobuf
98-
mv bin\protoc.exe D:\bin
103+
gh release download -R protocolbuffers/protobuf -p 'protoc-*-win32.zip' -O protoc.zip 'v23.2'
104+
if ( $LASTEXITCODE ) {
105+
Write-Output '::error::Could not download protoc.'
106+
exit $LASTEXITCODE
107+
}
108+
109+
tar.exe xf protoc.zip
110+
if ( $LASTEXITCODE ) {
111+
Write-Output '::error::Could not install protoc.'
112+
exit $LASTEXITCODE
113+
}
114+
115+
mkdir -f ${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim/protobuf
116+
mv include/* ${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim/protobuf
117+
118+
# put protoc in GOPATH to make things easier
119+
mv bin\protoc.exe (Join-Path (go env GOPATH) 'bin')
120+
env:
121+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99122

100123
- name: Run Protobuild
101124
shell: powershell
102125
run: |
103-
go install github.com/containerd/[email protected]
104-
cd go\src\github.com\Microsoft\hcsshim
105-
106-
$Env:Path += ";D:\bin;" + $Env:GOPATH + "\bin"
126+
Write-Output "::group::protobuild"
107127
protobuild $(go list ./... | grep -v /vendor/)
128+
Write-Output "::endgroup::"
129+
if ( $LASTEXITCODE ) {
130+
Write-Output '::error::Failed to run protobuild.'
131+
exit $LASTEXITCODE
132+
}
108133
134+
Write-Output "::group::git diff"
135+
# look for any new files not previously tracked
136+
git add --all --intent-to-add .
109137
git diff --exit-code
110-
env:
111-
GOPATH: '${{ github.workspace }}\go'
112-
GOFLAGS: ""
113-
GOPROXY: ""
138+
Write-Output "::endgroup::"
139+
working-directory: "${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim"
114140

115141
verify-vendor:
116-
runs-on: "windows-2019"
142+
runs-on: "windows-2022"
117143
env:
118144
GOPROXY: "https://proxy.golang.org,direct"
119145
steps:
120146
- uses: actions/checkout@v3
147+
121148
- uses: actions/setup-go@v4
122149
with:
123150
go-version: ${{ env.GO_VERSION }}
151+
124152
- name: Validate go.mod and vendoring
125153
shell: powershell
126154
run: |
@@ -130,6 +158,7 @@ jobs:
130158
Write-Error "Main modules are not up to date. Please validate your go version >= this job's and run `go mod vendor` followed by `go mod tidy` in the repo root path."
131159
}
132160
exit $process.ExitCode
161+
133162
- name: Validate test/go.mod
134163
shell: powershell
135164
working-directory: test
@@ -150,7 +179,7 @@ jobs:
150179
151180
go-gen:
152181
name: Go Generate
153-
runs-on: "windows-2019"
182+
runs-on: "windows-2022"
154183
steps:
155184
- uses: actions/checkout@v3
156185
- uses: actions/setup-go@v4
@@ -316,18 +345,15 @@ jobs:
316345
- name: Install crictl
317346
shell: powershell
318347
run: |
319-
$VerbosePreference = 'Continue'
320-
$ErrorActionPreference = 'Stop'
321-
322-
$crictlVersion = 'v1.24.2'
323-
$url = "https://github.com/kubernetes-sigs/cri-tools/releases/download/${crictlVersion}/crictl-${crictlVersion}-windows-amd64.tar.gz"
324-
curl.exe -L --no-progress-meter -o c:\crictl.tar.gz $url
325-
tar.exe xf c:\crictl.tar.gz -C "${{ github.workspace }}/bin"
348+
gh release download -R kubernetes-sigs/cri-tools -p 'crictl-*-windows-amd64.tar.gz' -O c:\crictl.tar.gz 'v1.24.2'
349+
tar.exe xf c:\crictl.tar.gz -C '${{ github.workspace }}/bin'
326350
327351
if ( $LASTEXITCODE ) {
328352
Write-Output '::error::Could not install crictl.'
329353
exit $LASTEXITCODE
330354
}
355+
env:
356+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
331357

332358
- name: Install mingw
333359
shell: powershell
@@ -472,7 +498,7 @@ jobs:
472498

473499
build:
474500
needs: [test-windows, test-linux]
475-
runs-on: "windows-2019"
501+
runs-on: "windows-2022"
476502
steps:
477503
- uses: actions/checkout@v3
478504
- uses: actions/setup-go@v4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ rootfs-conv/*
3737
deps/*
3838
out/*
3939

40+
# protobuf files
41+
# only files at root of the repo, otherwise this will cause issues with vendoring
42+
/protobuf/*
43+
4044
# test results
4145
test/results
4246

Protobuild.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ plugins = ["grpc", "fieldpath"]
99
# treat the root of the project as an include, but this may not be necessary.
1010
before = ["./protobuf"]
1111

12+
# defaults are "/usr/local/include" and "/usr/include", which don't exist on Windows.
13+
# override defaults to supress errors about non-existant directories.
14+
after = []
15+
1216
# Paths that should be treated as include roots in relation to the vendor
1317
# directory. These will be calculated with the vendor directory nearest the
1418
# target package.

0 commit comments

Comments
 (0)