Skip to content
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

Add sempahore auto go-build workflow #9589

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .semaphore/update-go-build-pins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: v1.0
name: Trigger calico/go-build update
agent:
machine:
type: f1-standard-2
os_image: ubuntu2204

execution_time_limit:
minutes: 30

global_job_config:
prologue:
commands:
- checkout

blocks:
- name: Auto calico/go-build update
task:
secrets:
- name: marvin-github-token
jobs:
- name: Auto calico/go-build update
commands:
- CONFIRM=true make git-config
- CONFIRM=true GITHUB_TOKEN=${MARVIN_GITHUB_TOKEN} make trigger-auto-pin-update-process
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ endif
python:3 \
bash -c '/usr/local/bin/python release/get-contributors.py >> /code/AUTHORS.md'

update-pins: update-go-build-pin

###############################################################################
# Post-release validation
###############################################################################
Expand Down
29 changes: 29 additions & 0 deletions lib.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,31 @@ define update_replace_pin
fi'
endef

# Get the latest release tag from projectcalico/go-build.
GO_BUILD_REPO=https://github.com/projectcalico/go-build.git
define get_go_build_version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should give the option for a specific version based on go version.

while on master it is fine to get the latest, as we create new branches, they should go based on their go version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This auto pin update is only planned for the master branch. This is triggered by calico/go-build after a successful tag build. It requires more detailed definition in calico/go-build to make branch auto pin update work properly.

$(shell git ls-remote --tags --refs --sort=-version:refname $(GO_BUILD_REPO) | head -n 1 | awk -F '/' '{print $$NF}')
endef

# update_go_build updates the GO_BUILD_VER in metadata.mk or Makefile.
# for annotated git tags, we need to remove the trailing `^{}`.
# for the obsoleted vx.y go-build version, we need to remove the leading `v` for bash string comparison to work properly.
define update_go_build_pin
$(eval new_ver := $(subst ^{},,$(call get_go_build_version)))
$(eval old_ver := $(subst v,,$(shell grep -E "^GO_BUILD_VER" $(1) | cut -d'=' -f2 | xargs)))

@echo "current GO_BUILD_VER=$(old_ver)"
@echo "latest GO_BUILD_VER=$(new_ver)"

bash -c '\
if [[ "$(new_ver)" > "$(old_ver)" ]]; then \
sed -i "s/^GO_BUILD_VER[[:space:]]*=.*/GO_BUILD_VER=$(new_ver)/" $(1); \
echo "GO_BUILD_VER is updated to $(new_ver)"; \
else \
echo "no need to update GO_BUILD_VER"; \
fi'
endef

GIT_REMOTE?=origin
API_BRANCH?=$(PIN_BRANCH)
API_REPO?=github.com/projectcalico/calico/api
Expand Down Expand Up @@ -393,6 +418,9 @@ update-cni-plugin-pin:
replace-cni-pin:
$(call update_replace_pin,github.com/projectcalico/calico/cni-plugin,$(CNI_REPO),$(CNI_BRANCH))

update-go-build-pin:
$(call update_go_build_pin,$(GIT_GO_BUILD_UPDATE_COMMIT_FILE))

git-status:
git status --porcelain

Expand Down Expand Up @@ -453,6 +481,7 @@ GIT_PR_BRANCH_BASE?=$(SEMAPHORE_GIT_BRANCH)
PIN_UPDATE_BRANCH?=semaphore-auto-pin-updates-$(GIT_PR_BRANCH_BASE)
GIT_PR_BRANCH_HEAD?=$(PIN_UPDATE_BRANCH)
GIT_PIN_UPDATE_COMMIT_FILES?=go.mod go.sum
GIT_GO_BUILD_UPDATE_COMMIT_FILE?=metadata.mk
GIT_PIN_UPDATE_COMMIT_EXTRA_FILES?=$(GIT_COMMIT_EXTRA_FILES)
GIT_COMMIT_FILES?=$(GIT_PIN_UPDATE_COMMIT_FILES) $(GIT_PIN_UPDATE_COMMIT_EXTRA_FILES)

Expand Down
Loading