From d257fa179b45aba5e319c14c02d959f9e66459df Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 6 Mar 2024 00:44:26 +0800 Subject: [PATCH] [CI] do not hardcode the Forgejo release in end-to-end testing Now that Forgejo has its own release number, use the Makefile as a reference. Also document and improve support for debugging this pull_request_target workflow by using a branch in the repository. --- .forgejo/cascading-pr-end-to-end | 27 ++++++++---- .../workflows/cascade-setup-end-to-end.yml | 43 +++++++++++++++++-- Makefile | 20 +++++++-- 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/.forgejo/cascading-pr-end-to-end b/.forgejo/cascading-pr-end-to-end index 975888b245..2350394f2c 100755 --- a/.forgejo/cascading-pr-end-to-end +++ b/.forgejo/cascading-pr-end-to-end @@ -5,17 +5,26 @@ set -ex end_to_end=$1 end_to_end_pr=$2 forgejo=$3 -forgejo_pr=$4 +forgejo_pr_or_ref=$4 + +cd $forgejo +full_version=$(make show-version-full) +major_version=$(make show-version-major) -head_url=$(jq --raw-output .head.repo.html_url < $forgejo_pr) -test "$head_url" != null -branch=$(jq --raw-output .head.ref < $forgejo_pr) -test "$branch" != null cd $end_to_end -echo $head_url $branch 7.0.0+0-gitea-1.22.0 > forgejo/sources/1.22 date > last-upgrade -base_url=$(jq --raw-output .base.repo.html_url < $forgejo_pr) -test "$base_url" != null +if test -f "$forgejo_pr_or_ref" ; then + forgejo_pr=$forgejo_pr_or_ref + head_url=$(jq --raw-output .head.repo.html_url < $forgejo_pr) + test "$head_url" != null + branch=$(jq --raw-output .head.ref < $forgejo_pr) + test "$branch" != null + echo $head_url $branch $full_version > forgejo/sources/$major_version +else + forgejo_ref=$forgejo_pr_or_ref + echo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY ${forgejo_ref#refs/heads/} $full_version > forgejo/sources/$major_version +fi + test "$GITHUB_RUN_NUMBER" -echo $base_url/actions/runs/$GITHUB_RUN_NUMBER/artifacts/forgejo > forgejo/binary-url +echo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_NUMBER/artifacts/forgejo > forgejo/binary-url diff --git a/.forgejo/workflows/cascade-setup-end-to-end.yml b/.forgejo/workflows/cascade-setup-end-to-end.yml index 235211f18a..e3b43d968b 100644 --- a/.forgejo/workflows/cascade-setup-end-to-end.yml +++ b/.forgejo/workflows/cascade-setup-end-to-end.yml @@ -1,5 +1,23 @@ +# Copyright 2024 The Forgejo Authors # SPDX-License-Identifier: MIT +# +# To modify this workflow: +# +# - push it to the wip-ci-end-to-end branch on the forgejo repository +# otherwise it will not have access to the secrets required to push +# the cascading PR +# +# - once it works, open a pull request for the sake of keeping track +# of the change even if the PR won't run it because it will use +# whatever is in the default branch instead +# +# - after it is merged, double check it works by setting the +# run-end-to-end-test on a pull request (any pull request will doe +# on: + push: + branches: + - 'wip-ci-end-to-end' pull_request_target: types: - labeled @@ -20,9 +38,18 @@ jobs: cat <<'EOF' ${{ toJSON(github.event.pull_request.labels.*.name) }} EOF + cat <<'EOF' + ${{ toJSON(github.event) }} + EOF build: - if: ${{ !startsWith(vars.ROLE, 'forgejo-') && github.event.action == 'label_updated' && contains(github.event.pull_request.labels.*.name, 'run-end-to-end-tests') }} + if: > + !startsWith(vars.ROLE, 'forgejo-') && ( + github.event_name == 'push' || + ( + github.event.action == 'label_updated' && contains(github.event.pull_request.labels.*.name, 'run-end-to-end-tests') + ) + ) runs-on: docker container: image: 'docker.io/node:20-bookworm' @@ -55,19 +82,29 @@ jobs: path: forgejo cascade: - if: ${{ !startsWith(vars.ROLE, 'forgejo-') && github.event.action == 'label_updated' && contains(github.event.pull_request.labels.*.name, 'run-end-to-end-tests') }} + if: > + !startsWith(vars.ROLE, 'forgejo-') && ( + github.event_name == 'push' || + ( + github.event.action == 'label_updated' && contains(github.event.pull_request.labels.*.name, 'run-end-to-end-tests') + ) + ) needs: [build] runs-on: docker container: image: node:20-bookworm steps: - uses: actions/checkout@v4 - - uses: actions/cascading-pr@v1 + with: + fetch-depth: '0' + show-progress: 'false' + - uses: actions/cascading-pr@v2 with: origin-url: ${{ env.GITHUB_SERVER_URL }} origin-repo: ${{ github.repository }} origin-token: ${{ secrets.END_TO_END_CASCADING_PR_ORIGIN }} origin-pr: ${{ github.event.pull_request.number }} + origin-ref: ${{ github.event_name == 'push' && github.event.ref }} destination-url: https://code.forgejo.org destination-fork-repo: cascading-pr/end-to-end destination-repo: forgejo/end-to-end diff --git a/Makefile b/Makefile index 9d0a92bdfb..bc3837f065 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,14 @@ ifneq ($(STORED_VERSION),) else FORGEJO_VERSION ?= $(shell git describe --exclude '*-test' --tags --always | sed 's/^v//')+${GITEA_COMPATIBILITY} endif +FORGEJO_VERSION_MAJOR=$(shell echo $(FORGEJO_VERSION) | sed -e 's/\..*//') + +show-version-full: + @echo ${FORGEJO_VERSION} + +show-version-major: + @echo ${FORGEJO_VERSION_MAJOR} + RELEASE_VERSION ?= ${FORGEJO_VERSION} VERSION ?= ${RELEASE_VERSION} @@ -100,8 +108,10 @@ LDFLAGS := $(LDFLAGS) -X "main.ReleaseVersion=$(RELEASE_VERSION)" -X "main.MakeV LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64 -GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) -GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) $(shell $(GO) list code.gitea.io/gitea/models/forgejo_migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) +ifeq ($(HAS_GO), yes) + GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) + GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) $(shell $(GO) list code.gitea.io/gitea/models/forgejo_migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) +endif FOMANTIC_WORK_DIR := web_src/fomantic @@ -140,7 +150,9 @@ GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/optio GO_SOURCES += $(GENERATED_GO_DEST) GO_SOURCES_NO_BINDATA := $(GO_SOURCES) -MIGRATION_PACKAGES := $(shell $(GO) list code.gitea.io/gitea/models/migrations/... code.gitea.io/gitea/models/forgejo_migrations/...) +ifeq ($(HAS_GO), yes) + MIGRATION_PACKAGES := $(shell $(GO) list code.gitea.io/gitea/models/migrations/... code.gitea.io/gitea/models/forgejo_migrations/...) +endif ifeq ($(filter $(TAGS_SPLIT),bindata),bindata) GO_SOURCES += $(BINDATA_DEST) @@ -219,6 +231,8 @@ help: @echo " - checks-frontend check frontend files" @echo " - checks-backend check backend files" @echo " - test test everything" + @echo " - show-version-full show the same version as the API endpoint" + @echo " - show-version-major show major release number only" @echo " - test-frontend test frontend files" @echo " - test-backend test backend files" @echo " - test-e2e[\#TestSpecificName] test end to end using playwright"