Repository navigation
Allow configuring the plugin-git version for local backend clone #7536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
6543
merged 5 commits into
woodpecker-ci:main
from
AhmadNajiKam:fix/local-plugin-git-download
Nov 11, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b251770
Verify plugin-git download in local backend
AhmadNajiKam 81e06b4
Fix some ci linting issues
AhmadNajiKam 928b114
Allow configuring the plugin-git version for local backend clone
AhmadNajiKam e61dd4d
Look up plugin-git release via GitHub API in local backend
AhmadNajiKam 91cca7d
Merge branch 'main' into fix/local-plugin-git-download
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // Copyright 2026 Woodpecker Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package local | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDownloadGitPluginBinary(t *testing.T) { | ||
| binary := []byte("plugin-git binary") | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| arch string | ||
| version string | ||
| assetCode int | ||
| wantAsset string | ||
| wantErr string | ||
| }{ | ||
| {name: "latest", arch: "arm64", assetCode: http.StatusOK, wantAsset: "/assets/linux-arm64_plugin-git"}, | ||
| {name: "pinned version", arch: "arm64", version: "2.12.1", assetCode: http.StatusOK, wantAsset: "/assets/linux-arm64_plugin-git"}, | ||
| {name: "arm does not match arm64", arch: "arm", assetCode: http.StatusOK, wantAsset: "/assets/linux-arm_plugin-git"}, | ||
| {name: "unknown version", arch: "arm64", version: "0.0.0", wantErr: "plugin-git release '0.0.0' does not exist"}, | ||
| {name: "unsupported arch", arch: "386", wantErr: "plugin-git release 'latest' has no binary for linux/386"}, | ||
| {name: "asset download error", arch: "arm64", assetCode: http.StatusBadGateway, wantErr: "unexpected status 502"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| var gotAsset string | ||
| mux := http.NewServeMux() | ||
| srv := httptest.NewServer(mux) | ||
| defer srv.Close() | ||
|
|
||
| release := func(w http.ResponseWriter, _ *http.Request) { | ||
| // arm64 is listed before arm, like in the real releases | ||
| fmt.Fprintf(w, `{"assets":[ | ||
| {"name":"checksums.txt","browser_download_url":"%[1]s/assets/checksums.txt"}, | ||
| {"name":"linux-amd64_plugin-git","browser_download_url":"%[1]s/assets/linux-amd64_plugin-git"}, | ||
| {"name":"linux-arm64_plugin-git","browser_download_url":"%[1]s/assets/linux-arm64_plugin-git"}, | ||
| {"name":"linux-arm_plugin-git","browser_download_url":"%[1]s/assets/linux-arm_plugin-git"} | ||
| ]}`, srv.URL) | ||
| } | ||
| mux.HandleFunc("/releases/latest", release) | ||
| mux.HandleFunc("/releases/tags/2.12.1", release) | ||
| mux.HandleFunc("/assets/", func(w http.ResponseWriter, r *http.Request) { | ||
| gotAsset = r.URL.Path | ||
| w.WriteHeader(tt.assetCode) | ||
| _, _ = w.Write(binary) | ||
| }) | ||
|
|
||
| orig := pluginGitReleaseAPI | ||
| pluginGitReleaseAPI = srv.URL + "/releases" | ||
| defer func() { pluginGitReleaseAPI = orig }() | ||
|
|
||
| e := &local{os: "linux", arch: tt.arch, pluginGitVersion: tt.version} | ||
| dest := filepath.Join(t.TempDir(), "plugin-git") | ||
| err := e.downloadGitPluginBinary(t.Context(), dest) | ||
|
|
||
| if tt.wantErr != "" { | ||
| assert.ErrorContains(t, err, tt.wantErr) | ||
| assert.NoFileExists(t, dest) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.wantAsset, gotAsset) | ||
| content, err := os.ReadFile(dest) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, binary, content) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.