Skip to content

Commit 5638d53

Browse files
authored
Merge branch 'master' into bump-golang.org/x/oauth2-v0.30.0
Signed-off-by: Junya Okabe <86868255+Okabe-Junya@users.noreply.github.com>
2 parents d2b1eb2 + dfb257e commit 5638d53

74 files changed

Lines changed: 6608 additions & 380 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
.DS_Store
15+
16+
# Binaries
17+
.artifacts
18+
19+
# docs
20+
docs
21+
22+
examples
23+
24+
# Go
25+
/vendor
26+
27+
# nodejs
28+
node_modules
29+
30+
# web
31+
web/node_modules
32+
web/dist
33+
web/.env
34+
web/.cache
35+
web/coverage
36+
pkg/app/web/.env
37+
38+
# IDE config files
39+
.ijwb
40+
.idea
41+
42+
.dev
43+
44+
# Terraform workspace
45+
.terraform
46+
.terraform-credentials
47+
48+
.rendered-manifests
49+
50+
# manifests
51+
manifests/*
52+
53+
# gomock generated reflect files
54+
gomock_reflect_*/
55+
56+
# Cache
57+
.cache
58+
59+
# hack
60+
hack/*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: plugin_release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to release (e.g. v0.1.0)"
8+
required: true
9+
path:
10+
description: "Plugin source path (e.g. pkg/app/pipedv1/plugin/kubernetes)"
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
release:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v5
22+
with:
23+
repository: pipe-cd/pipecd
24+
fetch-depth: 0
25+
- uses: actions/setup-go@v3
26+
with:
27+
go-version: ${{ env.GO_VERSION }}
28+
cache: true
29+
- name: Determine Plugin Info
30+
run: echo "PLUGIN_NAME=$(basename ${{ inputs.path }})" >> $GITHUB_ENV
31+
- name: Build binary artifacts
32+
run: |
33+
make build/plugin PLUGINS=$PLUGIN_NAME BUILD_OS=linux BUILD_ARCH=amd64 BIN_SUFFIX=_${{ inputs.version }}_linux_amd64
34+
make build/plugin PLUGINS=$PLUGIN_NAME BUILD_OS=linux BUILD_ARCH=arm64 BIN_SUFFIX=_${{ inputs.version }}_linux_arm64
35+
make build/plugin PLUGINS=$PLUGIN_NAME BUILD_OS=darwin BUILD_ARCH=amd64 BIN_SUFFIX=_${{ inputs.version }}_darwin_amd64
36+
make build/plugin PLUGINS=$PLUGIN_NAME BUILD_OS=darwin BUILD_ARCH=arm64 BIN_SUFFIX=_${{ inputs.version }}_darwin_arm64
37+
- env:
38+
INPUT_VERSION: ${{ inputs.version }}
39+
INPUT_PATH: ${{ inputs.path }}
40+
GH_TOKEN: ${{ github.token }}
41+
run: |
42+
LATEST_VERSION=$(git tag -l '${{ inputs.path }}/v*' | awk -F/ '{print $NF, $0}' | sort -k1 -V | tail -n1 | cut -d' ' -f2-)
43+
44+
if [[ -z "$LATEST_VERSION" ]]; then
45+
LATEST_VERSION=$(git log --format="%H" --reverse -- ./${{ inputs.path }}/ | head -n 1)
46+
fi
47+
48+
echo "Latest version: $LATEST_VERSION"
49+
echo "Input version: $INPUT_VERSION"
50+
if [[ "$LATEST_VERSION" == "$INPUT_VERSION" ]]; then
51+
echo "Version $INPUT_VERSION already exists"
52+
exit 0
53+
fi
54+
55+
cat > output.tmp <<EOF
56+
Plugin $PLUGIN_NAME Release $INPUT_VERSION with changes since $LATEST_VERSION
57+
---
58+
59+
EOF
60+
git log --reverse --format="* %s" $LATEST_VERSION..HEAD -- $INPUT_PATH | sed -E 's/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/pipe-cd\/pipecd\/pull\/\1))/g' >> output.tmp
61+
- name: Publish binary artifacts
62+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda #v2.2.1
63+
with:
64+
tag_name: ${{ inputs.path }}/${{ inputs.version }}
65+
body_path: output.tmp
66+
name: ${{ env.PLUGIN_NAME }} ${{ inputs.version }}
67+
target_commitish: ${{ github.sha }}
68+
draft: true
69+
make_latest: "false"
70+
files: |
71+
./.artifacts/plugins/${{ env.PLUGIN_NAME }}_${{ inputs.version }}_linux_amd64
72+
./.artifacts/plugins/${{ env.PLUGIN_NAME }}_${{ inputs.version }}_linux_arm64
73+
./.artifacts/plugins/${{ env.PLUGIN_NAME }}_${{ inputs.version }}_darwin_amd64
74+
./.artifacts/plugins/${{ env.PLUGIN_NAME }}_${{ inputs.version }}_darwin_arm64

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
# Go
2929
/vendor
30+
go.work
31+
go.work.sum
3032

3133
# nodejs
3234
node_modules

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ issues:
2929
exclude-dirs:
3030
- "vendor$"
3131
- "pkg/app/piped/executor/analysis/mannwhitney"
32+
# Relative path of "pkg/app/pipedv1/plugin/analysis/executestage/mannwhitney"
33+
- "executestage/mannwhitney"
3234
exclude-rules:
3335
- linters:
3436
- staticcheck

Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ run/pipecd: BUILD_LDFLAGS_PREFIX := -X github.com/pipe-cd/pipecd/pkg/version
154154
run/pipecd: BUILD_OPTS ?= -ldflags "$(BUILD_LDFLAGS_PREFIX).version=$(BUILD_VERSION) $(BUILD_LDFLAGS_PREFIX).gitCommit=$(BUILD_COMMIT) $(BUILD_LDFLAGS_PREFIX).buildDate=$(BUILD_DATE) -w"
155155
run/pipecd: CONTROL_PLANE_VALUES ?= ./quickstart/control-plane-values.yaml
156156
run/pipecd:
157-
@echo "Building go binary of Control Plane..."
158-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(BUILD_ENV) go build $(BUILD_OPTS) -o ./.artifacts/pipecd ./cmd/pipecd
159-
160-
@echo "Building web static files..."
161-
yarn --cwd web build
162-
163157
@echo "Building docker image and pushing it to local registry..."
164158
docker build -f cmd/pipecd/Dockerfile -t localhost:5001/pipecd:$(BUILD_VERSION) .
165159
docker push localhost:5001/pipecd:$(BUILD_VERSION)
@@ -319,3 +313,20 @@ setup-local-oidc:
319313
.PHONY: delete-local-oidc
320314
delete-local-oidc:
321315
docker compose -f ./hack/oidc/docker-compose.yml down
316+
317+
# Go workspace commands
318+
# These commands are used to manage go workspace.
319+
# It is useful when you want to develop SDK and test it in other modules.
320+
.PHONY: setup-go-workspace
321+
setup-go-workspace: MODULES ?= $(shell find . -name go.mod | while read -r dir; do dirname "$$dir"; done | paste -sd, -) # comma separated list of modules. eg: MODULES=.,pkg/plugin/sdk
322+
setup-go-workspace:
323+
@echo "Setting up go workspace..."
324+
go work init || true # ignore error if go workspace is already initialized
325+
@for module in $(shell echo $(MODULES) | tr ',' ' '); do \
326+
echo "Setting up module: $$module"; \
327+
go work use $$module; \
328+
done
329+
330+
.PHONY: teardown-go-workspace
331+
teardown-go-workspace:
332+
rm -f go.work go.work.sum

cmd/pipecd/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ FROM --platform=$BUILDPLATFORM node:20.19.0-alpine3.21 AS web
55

66
WORKDIR /app
77

8-
COPY . .
9-
108
RUN apk add --no-cache make git
119

12-
RUN make update/web-deps
10+
COPY web/package.json web/yarn.lock ./web/
11+
RUN yarn --cwd web install --prefer-offline
12+
13+
COPY .git ./.git
14+
COPY web ./web
15+
COPY Makefile .
1316
RUN make build/web
1417

1518
# pipecd builder
@@ -23,7 +26,9 @@ WORKDIR /app
2326
COPY go.* ./
2427
RUN go mod download
2528

26-
COPY . ./
29+
COPY pkg/ ./pkg/
30+
COPY cmd/ ./cmd/
31+
COPY Makefile .
2732

2833
RUN make build/go MOD=pipecd BUILD_OS=${TARGETOS} BUILD_ARCH=${TARGETARCH}
2934

pkg/app/pipectl/cmd/migrate/application_config.go

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21+
"io/fs"
22+
"maps"
2123
"os"
24+
"path/filepath"
2225

2326
"github.com/spf13/cobra"
2427
"go.uber.org/zap"
2528
"sigs.k8s.io/yaml"
2629

2730
"github.com/pipe-cd/pipecd/pkg/cli"
2831
"github.com/pipe-cd/pipecd/pkg/config"
32+
"github.com/pipe-cd/pipecd/pkg/model"
2933
)
3034

3135
type applicationConfig struct {
3236
root *command
3337

3438
configFiles []string
39+
directories []string
3540
}
3641

3742
func newApplicationConfigCommand(root *command) *cobra.Command {
@@ -46,11 +51,15 @@ func newApplicationConfigCommand(root *command) *cobra.Command {
4651
}
4752

4853
cmd.Flags().StringSliceVar(&c.configFiles, "config-files", c.configFiles, "The list of application config files to migrate.")
49-
cmd.MarkFlagRequired("config-files")
54+
cmd.Flags().StringSliceVar(&c.directories, "dirs", c.directories, "The list of application config directories to migrate.")
55+
56+
cmd.MarkFlagsOneRequired("config-files", "dirs")
57+
cmd.MarkFlagsMutuallyExclusive("config-files", "dirs")
5058
return cmd
5159
}
5260

5361
func (c *applicationConfig) run(ctx context.Context, input cli.Input) error {
62+
5463
for _, configFile := range c.configFiles {
5564
input.Logger.Info("migrating application config", zap.String("config-file", configFile))
5665
if err := c.migrateApplicationConfig(ctx, configFile, input.Logger); err != nil {
@@ -60,6 +69,37 @@ func (c *applicationConfig) run(ctx context.Context, input cli.Input) error {
6069
input.Logger.Info("successfully migrated application config", zap.String("config-file", configFile))
6170
}
6271

72+
for _, directory := range c.directories {
73+
input.Logger.Info("migrating application configs in directory", zap.String("directory", directory))
74+
75+
fileSystem := os.DirFS(directory)
76+
// Scan all files under the repository.
77+
err := fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
78+
if err != nil {
79+
return err
80+
}
81+
if d.IsDir() {
82+
return nil
83+
}
84+
if !model.IsApplicationConfigFile(d.Name()) {
85+
return nil
86+
}
87+
88+
input.Logger.Info("migrating application config", zap.String("config-file", path))
89+
if err := c.migrateApplicationConfig(ctx, filepath.Join(directory, path), input.Logger); err != nil {
90+
input.Logger.Error("failed to migrate application config", zap.String("config-file", path), zap.Error(err))
91+
// Continue to migrate other application configs.
92+
return nil
93+
}
94+
input.Logger.Info("successfully migrated application config", zap.String("config-file", path))
95+
return nil
96+
})
97+
if err != nil {
98+
input.Logger.Error("failed to migrate application configs in directory", zap.String("directory", directory), zap.Error(err))
99+
return err
100+
}
101+
input.Logger.Info("successfully migrated application configs in directory", zap.String("directory", directory))
102+
}
63103
return nil
64104
}
65105

@@ -89,7 +129,6 @@ func (c *applicationConfig) migrateApplicationConfig(_ context.Context, configFi
89129
"description",
90130
"planner",
91131
"commitMatcher",
92-
"pipeline",
93132
"trigger",
94133
"postSync",
95134
"timeout",
@@ -107,6 +146,37 @@ func (c *applicationConfig) migrateApplicationConfig(_ context.Context, configFi
107146
}
108147
}
109148

149+
var hasAnalysisStage bool
150+
151+
if oldPipelineCfg, ok := oldSpec["pipeline"]; ok {
152+
pipelineCfg := make(map[string][]any)
153+
154+
for _, oldStage := range oldPipelineCfg.(map[string]any)["stages"].([]any) {
155+
if oldStageCfg, ok := oldStage.(map[string]any); ok {
156+
// Check if the stage is the analysis stage to determine if we need to fill plugins.analysis config
157+
if oldStageCfg["name"] == string(model.StageAnalysis) {
158+
hasAnalysisStage = true
159+
}
160+
161+
// Copy STAGE `timeout` and `skipOn` config under pipeline.stages[].with to pipeline.stages[]
162+
// NOTE: We keep the original `timeout` and `skipOn` config under pipeline.stages[].with. for backward compatibility,
163+
// in case user want to downgrade pipedv1 to pipedv0.
164+
// `pipeline.stages[].with.{timeout, skipOn}` will be marked as deprecated in v1.
165+
stageCfg := maps.Clone(oldStageCfg)
166+
if withCfg, ok := stageCfg["with"].(map[string]any); ok {
167+
if _, ok := withCfg["timeout"]; ok {
168+
stageCfg["timeout"] = withCfg["timeout"]
169+
}
170+
if _, ok := withCfg["skipOn"]; ok {
171+
stageCfg["skipOn"] = withCfg["skipOn"]
172+
}
173+
}
174+
pipelineCfg["stages"] = append(pipelineCfg["stages"], stageCfg)
175+
}
176+
}
177+
spec["pipeline"] = pipelineCfg
178+
}
179+
110180
switch config.Kind(cfg["kind"].(string)) {
111181
case config.KindKubernetesApp:
112182
logger.Info("migrating kubernetes application config", zap.String("config-file", configFile))
@@ -126,6 +196,24 @@ func (c *applicationConfig) migrateApplicationConfig(_ context.Context, configFi
126196
pluginCfg["kubernetes"][key] = oldSpec[key]
127197
}
128198
}
199+
200+
// Add analysis stage configuration if it exists
201+
// namespace value will be set using spec.input.namespace
202+
if hasAnalysisStage {
203+
namespace := "default"
204+
if input, ok := oldSpec["input"].(map[string]any); ok {
205+
if ns, ok := input["namespace"].(string); ok && ns != "" {
206+
namespace = ns
207+
}
208+
}
209+
210+
pluginCfg["analysis"] = map[string]any{
211+
"appCustomArgs": map[string]string{
212+
"k8sNamespace": namespace,
213+
},
214+
}
215+
}
216+
129217
spec["plugins"] = pluginCfg
130218
case config.KindTerraformApp:
131219
logger.Info("migrating terraform application config", zap.String("config-file", configFile))

0 commit comments

Comments
 (0)