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

feat: add release markers #170

Merged
merged 5 commits into from
Mar 4, 2025
Merged

Conversation

rubenruizdegauna
Copy link
Contributor

@rubenruizdegauna rubenruizdegauna commented Feb 26, 2025

This PR will add release information to a file in the bucket where the package is being released.

After the lock is executed, an entry with start time will be appended to repo_path_root_dir/releases.json.
Just before the lock is released the entry will be loaded, end time will be set, and file will be persisted.

Example of data persisted:

[
  {
    "app_name": "newrelic-infra",
    "tag": "1.7.0",
    "run_id": "13549016185",
    "start": "2025-02-26T16:57:33Z",
    "end": "2025-02-26T16:58:47Z",
    "repo_name": "newrelic/infrastructure-agent",
    "schema": "custom",
    "schema_url": "https://raw.githubusercontent.com/newrelic/infrastructure-agent/test_publish_action_markers/build/upload-schema-linux-deb.yml"
  },
  {
    "app_name": "newrelic-infra",
    "tag": "1.7.0",
    "run_id": "13549016185",
    "start": "2025-02-26T16:58:53Z",
    "end": "2025-02-26T17:00:55Z",
    "repo_name": "newrelic/infrastructure-agent",
    "schema": "custom",
    "schema_url": "https://raw.githubusercontent.com/newrelic/infrastructure-agent/test_publish_action_markers/build/upload-schema-linux-rpm.yml"
  },
  {
    "app_name": "newrelic-infra",
    "tag": "1.7.0",
    "run_id": "13549016185",
    "start": "2025-02-26T17:01:01Z",
    "end": "2025-02-26T17:01:12Z",
    "repo_name": "newrelic/infrastructure-agent",
    "schema": "custom",
    "schema_url": "https://raw.githubusercontent.com/newrelic/infrastructure-agent/test_publish_action_markers/build/upload-schema-linux-targz.yml"
  }
]

Caveats: One release can call multiple times to the publish action. For example, the Infra Agent calls it once per package type (deb, rpm, tar.gz...). So multiple entries will be present for a release.

Ideally we would have just one, but then we need to move the responsibility to the user of the action.

This can be the first approach and we can discuss improvements.

@rubenruizdegauna rubenruizdegauna force-pushed the feat/add_release_markers branch 7 times, most recently from b49b8d7 to 944b7c9 Compare February 26, 2025 16:21
Comment on lines +38 to +39
SchemaURL string
Schema string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the config so we can show this information in the release markersr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since they were already provided in the action, no change is needed in the inputs, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. They were used only to process them, download, and get the local path of the schema.

@rubenruizdegauna rubenruizdegauna marked this pull request as ready for review February 27, 2025 07:34
@rubenruizdegauna rubenruizdegauna requested review from a team February 27, 2025 07:40
Copy link
Contributor

@sigilioso sigilioso left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this! It will definitely help troubleshooting 🎉

I've left some comments for us to discuss 🙂

I think we should add some docs regarding the markers somewhere, could we use the README?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should re-try por particular errors. Eg: error reading the markers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would leave it as an improvement in a separate PR. WDYT?

Comment on lines +172 to +178
objOutput, err := s.client.GetObject(&s3.GetObjectInput{
Bucket: aws.String(s.conf.Bucket),
Key: aws.String(s.markerPath()),
})
if err != nil {
return nil, fmt.Errorf("cannot read marker file: %w", err)
}
Copy link
Contributor

@sigilioso sigilioso Feb 27, 2025

Choose a reason for hiding this comment

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

Is the markers file supposed to exist or will the action create it the first time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I totally missed that!

	if err != nil {
		if !isNoSuchKeyError(err) {
			return Mark{}, err
		}

Shall we add a comment there to make more obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Added in 27048d7

@sigilioso sigilioso requested a review from a team February 27, 2025 11:53
@rubenruizdegauna rubenruizdegauna requested review from sigilioso and a team February 27, 2025 13:41
sigilioso
sigilioso previously approved these changes Mar 3, 2025
Copy link
Contributor

@sigilioso sigilioso left a comment

Choose a reason for hiding this comment

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

LGTM

Although I'd love to have another pair of eyes here 👀

By the way, how are we enforcing its usage?

🤔 If anybody is using v1.X.Y (lower than latest or a commit) the release info will not appear in the file.

@sigilioso sigilioso requested review from a team March 3, 2025 09:37
return ErrLastMarkerEnded
}

if lastMarker.AppName != mark.AppName || !lastMarker.Start.Equals(mark.Start) {

Choose a reason for hiding this comment

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

Are packages uploaded 1 by 1 always? What if multiple teams try to release at the same time? This tool doesn't allow for it. Should this be allowed in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a locking mechanism to prevent multiple actions running at the same time within the same S3 Bucket.

https://github.com/newrelic/infrastructure-publish-action/blob/main/publisher/lock/lock.go

@rubenruizdegauna
Copy link
Contributor Author

LGTM

Although I'd love to have another pair of eyes here 👀

By the way, how are we enforcing its usage?

🤔 If anybody is using v1.X.Y (lower than latest or a commit) the release info will not appear in the file.
For now, we are only enforcing to v1 users. We need to think how to handle it (this is out of the scope of this PR, we need a Feature to work on the whole initiative)

Comment on lines +539 to +546
ReleaseInfo: ReleaseInfo{
AppName: "my-app",
Tag: "v1.2",
RunID: "run3",
RepoName: "repo3",
Schema: "schema3",
SchemaURL: "url3",
},

Choose a reason for hiding this comment

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

(future) I see a lot of repetitions between tests. Maybe we could benefit from having some "basis" variables to reuse on the tests. Maybe is a terrible idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a good idea :) . We could use stubs with https://github.com/brianvoe/gofakeit for example

@rubenruizdegauna rubenruizdegauna merged commit 4b7720c into main Mar 4, 2025
5 checks passed
@rubenruizdegauna rubenruizdegauna deleted the feat/add_release_markers branch March 4, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants