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 PULLREQUEST_DRONE_PULL_REQUEST drone env #3939

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

6543
Copy link
Member

@6543 6543 commented Jul 19, 2024

#3909 (comment)

cc @wez are you sure its PULLREQUEST_DRONE_PULL_REQUEST and not DRONE_PULL_REQUEST

@6543 6543 added the build_pr_images If set, the CI will build images for this PR and push to Dockerhub label Jul 19, 2024
@wez
Copy link
Contributor

wez commented Jul 19, 2024

@6543 yeah, that env var is definitely the setting I use to get this particular thing to work

@6543
Copy link
Member Author

6543 commented Jul 19, 2024

@wez does the server run on x86 ?

@wez
Copy link
Contributor

wez commented Jul 19, 2024

I run this particular configuration on amd64 and aarch64; so intel and arm, but 64-bit only

@wez
Copy link
Contributor

wez commented Jul 19, 2024

For clarity, I have an amd64 agent and an aarch64 agent. They both build their respective platform packages and docker image, and they both have a step that tries to merge the other architectures together into a multiarch image with plugins/manifest, so I have merge-docker-image-arm and merge-docker-image step as platform-dependent steps in that particular matrix workflow, and they "race" to merge the manifest together. They are set to failure: ignore because one of them will always lose the race.

@6543
Copy link
Member Author

6543 commented Jul 19, 2024

Well in this case the server image woodpeckerci/woodpecker-server:pull_3939 (x84 only) in combination with the newest 2.7.0 agent images should do it

@6543 6543 added the enhancement improve existing features label Jul 19, 2024
@6543 6543 requested a review from a team July 19, 2024 14:00
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.83%. Comparing base (7903d6f) to head (41dc7a2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3939      +/-   ##
==========================================
+ Coverage   26.80%   26.83%   +0.02%     
==========================================
  Files         394      394              
  Lines       27496    27507      +11     
==========================================
+ Hits         7370     7381      +11     
  Misses      19425    19425              
  Partials      701      701              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wez
Copy link
Contributor

wez commented Jul 19, 2024

Thanks; I appreciate you doing this, but I'm not sure if I'll be able to try that out today ahead of this being merged as I had to roll back to 2.6 (and reinstall/reconfigure, because there isn't a backwards db migration!) and I had to unblock some other work for today.

@qwerty287 qwerty287 changed the title Add quirk of PULLREQUEST_DRONE_PULL_REQUEST not to be "" Add PULLREQUEST_DRONE_PULL_REQUEST drone env Jul 19, 2024
@qwerty287 qwerty287 merged commit 54b91db into woodpecker-ci:main Jul 19, 2024
9 checks passed
@qwerty287 qwerty287 deleted the droneCompatibilityQuirks branch July 19, 2024 15:15
@woodpecker-bot
Copy link
Collaborator

This was referenced Jul 19, 2024
6543 added a commit to 6543-forks/woodpecker that referenced this pull request Sep 5, 2024
@woodpecker-bot woodpecker-bot mentioned this pull request Sep 8, 2024
1 task
wez added a commit to KumoCorp/kumomta that referenced this pull request Oct 31, 2024
This reverts commit 401df30.

The docker merge step is failing:

```
envconfig.Process: assigning PULLREQUEST_DRONE_PULL_REQUEST to Number: converting '' to type int. details: strconv.ParseInt: parsing "": invalid syntax
```

It seems that the compatibility change in
woodpecker-ci/woodpecker#3939 isn't sufficient.

Let's see if we can still run with the environment set manually,
or if we'll need to blackjack our own woodpecker plugin for this.
@wez
Copy link
Contributor

wez commented Oct 31, 2024

FWIW, I got around to upgrading to 2.7.1 recently and I just noticed that this is failing for the non-pr case:

envconfig.Process: assigning PULLREQUEST_DRONE_PULL_REQUEST to Number: converting '' to type int. details: strconv.ParseInt: parsing "": invalid syntax

It seems like the compatibility layer doesn't guarantee that this env var is not set to an empty string somewhere.

if env["CI_COMMIT_PULL_REQUEST"] == "" {
env["PULLREQUEST_DRONE_PULL_REQUEST"] = "0"
}

this logic looks like it might potentially be problematic, because it checks a different variable for empty, but I think it is "fine" because the variable it checks was the source of this one. So it's probably ok?

Somehow the plugin thinks this env var is empty though.

I wonder if perhaps neither of these are set when building on the main branch, and that it is the plugin that is inferring an empty string?

Here's the definition of the struct in that plugin:
https://github.com/drone-plugins/drone-manifest/blob/af5721dace68ce1cacae7fccdf948efda66da35a/plugin/pipeline.go#L81-L84

	// PullRequest provides the pull request metadata.
	PullRequest struct {
		Number int `envconfig:"DRONE_PULL_REQUEST"`
	}

I'm not familiar enough with go to know how to reason about the behavior of this.

wez added a commit to KumoCorp/kumomta that referenced this pull request Oct 31, 2024
This reverts commit 401df30.

The docker merge step is failing:

```
envconfig.Process: assigning PULLREQUEST_DRONE_PULL_REQUEST to Number: converting '' to type int. details: strconv.ParseInt: parsing "": invalid syntax
```

It seems that the compatibility change in
woodpecker-ci/woodpecker#3939 isn't sufficient.

Let's see if we can still run with the environment set manually,
or if we'll need to blackjack our own woodpecker plugin for this.
@6543
Copy link
Member Author

6543 commented Oct 31, 2024

@wez this patch is in the main branch targeting the release of v3.0.0 ... so it's not released jet

@6543
Copy link
Member Author

6543 commented Oct 31, 2024

or do you men to do:

 if env["CI_COMMIT_PULL_REQUEST"] == "" { 
 	env["PULLREQUEST_DRONE_PULL_REQUEST"] = "0"
+	env["DRONE_PULL_REQUEST"] = "0"
 }

?

@wez
Copy link
Contributor

wez commented Oct 31, 2024

It not being present in 2.7.1 definitely explains it!

I think this might be clearer logic:

- if env["CI_COMMIT_PULL_REQUEST"] == "" { 
+ if env["PULLREQUEST_DRONE_PULL_REQUEST"] == "" { 
 	env["PULLREQUEST_DRONE_PULL_REQUEST"] = "0"
 }

I reverted back to the deprecated environment setting syntax, and my pipeline succeeds, so I think I'm good to punt until 3.0.0 is released. The only consequence is that it is flagged with 39 warnings, so it may be difficult to notice future issues. I'll survive :)

@6543
Copy link
Member Author

6543 commented Oct 31, 2024

ah @wez you struggle with the fact that if you set environment, the plugin will not be considered as plugin anymore ... (security stuff)

@wez
Copy link
Contributor

wez commented Oct 31, 2024

I'm not sure that I understand what you mean there.

I have this in my config, on 2.7.1:

  merge-docker-image-arm:
    depends_on: [build-docker-image-arm]
    when:
      - evaluate: 'platform == "linux/aarch64" && UBUNTU_IMAGE == "ubuntu:22.04" && CI_PIPELINE_EVENT == "tag"'
    image: plugins/manifest
    failure: ignore
    environment: &docker_manifest_env
      # Legacy env var to prevent the plugin from throwing an error
      # when converting an empty string to a number
      PULLREQUEST_DRONE_PULL_REQUEST: 0
    settings: &docker_manifest_settings_tag
      <<: *docker_credentials
      target: "ghcr.io/kumocorp/kumomta-dev"
      template: "ghcr.io/kumocorp/kumomta:${CI_COMMIT_TAG}-ARCH"
      tags:
        - latest
        - ${CI_COMMIT_TAG}
      platforms:
        - linux/amd64
        - linux/arm64

the presence of the environment block yields a lot of warnings in the UI, but the step does run successfully.

I understand that the removal of the environment block is to address a potential security issue, but it doesn't appear to block me from running this config.

@woodpecker-bot woodpecker-bot mentioned this pull request Dec 14, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build_pr_images If set, the CI will build images for this PR and push to Dockerhub enhancement improve existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants