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

fix(ci): change ephemeral env to use github labels instead of comments #31340

Merged
merged 10 commits into from
Jan 29, 2025

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Dec 8, 2024

SUMMARY

Use labels instead of issue comment to spin up new environments, this is a safer approach, labels can only be added to PRs by users with write access to the repo. Also using labels it's possible to get the pushed_at to sanity check what we are building.

Use testenv-up labels to spin ephemeral envs

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions bot added the github_actions Pull requests that update GitHub Actions code label Dec 8, 2024
Comment on lines 47 to 50
- name: Debug
id: get-sha
run: |
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT

Choose a reason for hiding this comment

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

You should exit early if the PR was updated after the comment. See https://github.com/apache/camel/blob/66fbdcd2c71a6588bacd7b3e0d2a03128c0cd069/.github/workflows/pr-comment.yml#L55-L57

Suggested change
- name: Debug
id: get-sha
run: |
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT
- name: Debug
id: get-sha
env:
COMMENT_AT: ${{ github.event.comment.created_at }}
PUSHED_AT: ${{ fromJSON(steps.get-pr-info.outputs.result).pushed_at }}
run: |
if [[ $(date -d "$PUSHED_AT" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
exit 1
fi
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT

Choose a reason for hiding this comment

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

Unfortunately, this is not useful as pushed_at field is deprecated and the value will be nil.

Choose a reason for hiding this comment

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

I don't see any evidence of that in the documentation. Can you point me to your source?

Choose a reason for hiding this comment

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

Copy link

@avivkeller avivkeller Dec 10, 2024

Choose a reason for hiding this comment

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

Got it, thanks! In that case, alternative methods to verify the time of commit push should be used. (But some sort of verification is still needed)

Choose a reason for hiding this comment

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

If untrusted code needs to be run, I would move the IssueOps workflow to a Label gate (pull_request + label). There is no way to get a trustful commit date.

Copy link
Member

Choose a reason for hiding this comment

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

just to tie things together: pushed_at from https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request is slightly different from Commit.pushedDate, but I suppose the they're ultimately populated from the same source, so both are deprecated/going away? This wasn't obvious to me before but would make sense. I didn't see anything in https://docs.github.com/en/rest/about-the-rest-api/breaking-changes but I guess it just somewhat follows from https://docs.github.com/en/graphql/overview/breaking-changes .

Copy link
Member Author

Choose a reason for hiding this comment

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

@pwntester @raboof sorry for the delay here. I've updated to workflow to use PR labels, would be great if you can review it again

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 27, 2025
@dpgaspar dpgaspar requested review from raboof and pwntester January 27, 2025 12:47
@dpgaspar dpgaspar changed the title fix(ci): ephemeral get SHA fix(ci): change ephemeral env to use github labels instead of comments Jan 27, 2025
Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@ Ephemeral environment spinning up at http://34.216.170.82:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Comment on lines 60 to 70
- name: Check if a commit was pushed after PR was labeled
id: get-sha
env:
COMMENT_AT: ${{ github.event.pull_request.updated_at }}
PUSHED_AT: ${{ fromJSON(steps.get-pr-info.outputs.result).pushed_at }}
run: |
if [[ $(date -d "$PUSHED_AT" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
echo "Commit was pushed after the PR was updated."
exit 1
fi
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT

Choose a reason for hiding this comment

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

If you're verifying the label, there is no need for this extra step. Just use github.event.pull_request.head.sha

Copy link
Member Author

Choose a reason for hiding this comment

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

unsure if github.event.pull_request.updated_at could be greater then the time of the last push

Choose a reason for hiding this comment

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

No, it’s the SHA at the time of label, which is the most secure

Copy link
Member

Choose a reason for hiding this comment

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

GITHUB_RUN_ID can we useful at times too, not sure if it's better than SHA here, but would allow concurrent runs on the same SHA (do we want that? how do we want to handle potential SHA collisions?)

Copy link
Member

Choose a reason for hiding this comment

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

I see we have the concurrency GHA thing set up properly, meaning a new request will kill the previous ones, which I believe is what we want. Using the GITHUB_RUN_ID as a unique id on the AWS-side could help segment/isolate/clarify the runs.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we need something deterministic that we can use to kill previous instances on PR close or unlabelling on the AWS side, so GITHUB_RUN_ID isn't the best for that ...

Copy link
Member

@mistercrunch mistercrunch Jan 28, 2025

Choose a reason for hiding this comment

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

Side note, I created supersetbot to make it easier to develop/test/deploy things outside of GHA. We're pretty deep already here so we may not want to take this on, but we could move the bulk of the logic to supersetbot ephemeral deploy {image_id}, supersetbot ephemeral stop {image_id} ...

Copy link
Member Author

Choose a reason for hiding this comment

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

concurrency seems fine to me (pushed a fix). it's unique at the PR level, so label events for new commits will cancel previous runs.

+1 on using supersetbot ephemeral deploy

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@ Ephemeral environment spinning up at http://34.209.140.91:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

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

I'm sorry if my comments are confusing. If you'd like, I can PR into your branch with my suggested changes

Comment on lines 7 to 9
pull_request:
types:
- labeled

Choose a reason for hiding this comment

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

Keep in mind, pull_request_target must be used if you want to use secrets.

Comment on lines 56 to 87
- name: Get PR Info
uses: actions/github-script@v7
id: get-pr-info
with:
script: |
const pull_number = context.payload.pull_request
? context.payload.pull_request.number
: context.payload.inputs.issue_number;

if (!pull_number) {
throw new Error("Pull request number is not available.");
}

const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number,
});

return pr.data;

- name: Check if a commit was pushed after PR was labeled
id: get-sha
env:
COMMENT_AT: ${{ github.event.pull_request.updated_at }}
PUSHED_AT: ${{ fromJSON(steps.get-pr-info.outputs.result).pushed_at }}
run: |
if [[ $(date -d "$PUSHED_AT" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
echo "Commit was pushed after the PR was updated."
exit 1
fi
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT
Copy link

@avivkeller avivkeller Jan 28, 2025

Choose a reason for hiding this comment

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

as I mentioned in my other review, this entire segment is not needed when not triggering on a dispatch, and could result in a race condition (albeit harmless unless the trigger is pull_request_target)

I suggest ONLY fetching the SHA via this method when executing on dispatch rather than on PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok removed

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

LGTM! - and they envs are broken so this can only help.

I did some complementary work here #32017

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

@dpgaspar dpgaspar requested a review from avivkeller January 29, 2025 12:15
Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@dpgaspar Ephemeral environment spinning up at http://52.33.205.29:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@dpgaspar
Copy link
Member Author

@mistercrunch @avivkeller thank you for the reviews!

@dpgaspar dpgaspar merged commit e4bdb28 into apache:master Jan 29, 2025
40 checks passed
@dpgaspar dpgaspar deleted the fix/ephemeral-get-sha branch January 29, 2025 13:57
tmsjordan pushed a commit to tmsdevelopment/superset that referenced this pull request Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update GitHub Actions code size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants