Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

v1v
Copy link
Member

@v1v v1v commented Mar 8, 2024

What does this pull request do?

Use https://test.pypi.org/ to test the Release GitHub workflow on main and skip push changes. If a release tag then it behaves as usual, publishing the release.

Related issues

Closes #1994

Implementation details

It skips anything related to pushing the docker images, lambda functions or GitHub releases.

Potentially we could use a different AWS account or docker registry, though those steps are only about pushing the changes. If needed we can do a follow-up.

Test

I created a feature branch called test/release based on this PR, and the build is now running, see here

It failed with

Notice: Attempting to perform trusted publishing exchange to retrieve a temporary short-lived API token for authentication against https://test.pypi.org/legacy/ due to __token__ username with no supplied password field
Error: Trusted publishing exchange failure: 
Token request failed: the server refused the request for the following reasons:

* `invalid-publisher`: valid token, but no corresponding publisher (All lookup strategies exhausted)

This generally indicates a trusted publisher configuration error, but could
also indicate an internal error on GitHub or PyPI's part.


The claims rendered below are **for debugging purposes only**. You should **not**
use them to configure a trusted publisher unless they already match your expectations.

If a claim is not present in the claim set, then it is rendered as `MISSING`.

* `sub`: `repo:elastic/apm-agent-python:environment:release`
* `repository`: `elastic/apm-agent-python`
* `repository_owner`: `elastic`
* `repository_owner_id`: `6764390`
* `job_workflow_ref`: `elastic/apm-agent-python/.github/workflows/release.yml@refs/heads/test/release`
* `ref`: `refs/heads/test/release`

@v1v v1v requested review from a team March 8, 2024 14:55
@v1v v1v self-assigned this Mar 8, 2024
Copy link
Member

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

Thanks @v1v !

@v1v v1v requested a review from xrmx March 8, 2024 15:49
@v1v
Copy link
Member Author

v1v commented Mar 11, 2024

@xrmx , I might need your help with this approach:

PyPI does not allow for a filename to be reused, even once a project has been deleted and recreated.

Then, a second run failed:

https://github.com/elastic/apm-agent-python/actions/runs/8229823579/job/22501787751

What do you suggest?

@xrmx
Copy link
Member

xrmx commented Mar 11, 2024

@v1v can we postfix a +$GITHASH to the release version? See https://peps.python.org/pep-0440/#adding-local-version-identifiers, the paragraph before last.

@v1v
Copy link
Member Author

v1v commented Mar 11, 2024

can we postfix a +$GITHASH to the release version? See https://peps.python.org/pep-0440/#adding-local-version-identifiers, the paragraph before last.

Nice, but I have no clue how to do it; I can try to figure out but if you know how to, would you mind contributing to this PR? 🙏

@xrmx
Copy link
Member

xrmx commented Mar 11, 2024

can we postfix a +$GITHASH to the release version? See https://peps.python.org/pep-0440/#adding-local-version-identifiers, the paragraph before last.

Nice, but I have no clue how to do it; I can try to figure out but if you know how to, would you mind contributing to this PR? 🙏

Sure, will take a look later today

reakaleek
reakaleek previously approved these changes Mar 11, 2024
@xrmx
Copy link
Member

xrmx commented Mar 11, 2024

@v1v What do you think about somethings like this

diff --git a/setup.py b/setup.py
index 23ebec33..235bf4d8 100644
--- a/setup.py
+++ b/setup.py
@@ -100,7 +100,11 @@ def get_version():
     for line in version_file:
         if line.startswith("__version__"):
             version_tuple = ast.literal_eval(line.split(" = ")[1])
-            return ".".join(map(str, version_tuple))
+            version_str = ".".join(map(str, version_tuple))
+            local_version = os.getenv("ELASTIC_CI_LOCAL_VERSION")
+            if local_version:
+                return f"{version_str}+{local_version}"
+            return version_str
     return "unknown"

and then exposing to the packages workflow an ELASTIC_CI_LOCAL_VERSION environment variable with the value of ${{ github.run_id }}?

@v1v
Copy link
Member Author

v1v commented Mar 11, 2024

@xrmx, quick question:

+            local_version = os.getenv("ELASTIC_CI_LOCAL_VERSION")
+            if local_version:

if ELASTIC_CI_LOCAL_VERSION='' will it go through the if local_version condition?

Rationale:

I want to use a top-level environment variable, with something like:

# .github/workflows/release.yml
...

env:
  ELASTIC_CI_LOCAL_VERSION: ${{ startsWith(github.ref, 'refs/tags') && '' ||  github.run_id }}
jobs:
  ...

Then ELASTIC_CI_LOCAL_VERSION='' if a tag release, otherwise ELASTIC_CI_LOCAL_VERSION=${{ github.run_id }}

I need to find how to use the ternary in GitHub actions

@xrmx
Copy link
Member

xrmx commented Mar 11, 2024

Empty string is fine, code checks for a truthy value and empty string is not. Unless you are sending the single quotes

@v1v
Copy link
Member Author

v1v commented Mar 11, 2024

no single quotes, but empty instead, single quotes will be empty in this particular case, I think that's the way to set empty env variables

xrmx and others added 2 commits March 11, 2024 17:53
Make it possible to add a post version (per PEP-440) to the current agent
version at build time. This will be useful because we want to continuously
build the agent on CI and avoid version conflicts when publishing to test pypi.
So when returning the agent version add anything that has been passed
in ELASTIC_CI_POST_VERSION environment variable as post version.

Refs elastic#1994
@v1v v1v requested review from xrmx and reakaleek March 13, 2024 13:47
Copy link
Member

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

Thanks!

@xrmx xrmx merged commit 84688df into elastic:main Mar 13, 2024
xrmx added a commit that referenced this pull request Mar 20, 2024
* ci: run the release when merges to main

* avoid wrong docker-tag name

* use the opposite

* fix yaml

* enable test, slack message conditional and fix names

* Update .github/workflows/release.yml

* skip test for branches in the release workflow

* workaround

* fix

* Update .github/workflows/release.yml

* support releases in test.pypi for commits on main

* set environment variable in the reusable workflow instead

env propagation between reusable workflow is not supported

* setup: take a post version from environment variable

* Update .github/workflows/release.yml

---------

Co-authored-by: Riccardo Magliocchetti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Make it possible to build test artifacts
4 participants