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

chore(scripts): fix stable release promote script #13204

Merged
merged 6 commits into from May 17, 2024

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented May 7, 2024

This fixes the promote command to use the right payload...

Switches from GH_ to GITHUB_TOKEN as well and adds gh_auth for completeness.

@mafredri mafredri self-assigned this May 7, 2024
@mafredri mafredri force-pushed the mafredri/chore-scripts-fix-release-promote-env branch from 4bd38cd to 40651dd Compare May 7, 2024 19:02
@mafredri mafredri force-pushed the mafredri/chore-scripts-fix-release-promote-env branch from 40651dd to cb9f2d1 Compare May 7, 2024 19:05
Copy link
Collaborator

@stirby stirby left a comment

Choose a reason for hiding this comment

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

Glad to see you found the issue. Nice!

Just giving my ack here, should await devs' review.

@@ -4,6 +4,9 @@ set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

# Make sure GITHUB_TOKEN is set for the release command.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This only works when CODER=true i.e. inside a Coder workspaces.

Copy link
Member

Choose a reason for hiding this comment

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

Do we suggest adding an extra "echo" to indicate it?

Copy link
Member Author

Choose a reason for hiding this comment

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

That’s the expected use-case. And if it isn’t set outside a workspace it’ll print a notice to do gh auth login. Just realized that won’t work though, but we could update lib.sh to fetch the token via gh auth token in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we also shouldn't override GITHUB_TOKEN if it's set? And maybe support GH_TOKEN too (in lib.sh)? Thoughts @matifali?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes as far it works and make it more robust. Let's do this. I don't fully understand the difference between GH_ and GITHUB_ prefix for tokens.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think GH_ is legacy, sometimes still used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored it a bit @matifali, if it still looks alright to you, I'll go ahead and merge: 9417866

@@ -4,6 +4,9 @@ set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

# Make sure GITHUB_TOKEN is set for the release command.
Copy link
Member

Choose a reason for hiding this comment

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

Do we suggest adding an extra "echo" to indicate it?

scripts/lib.sh Outdated
@@ -144,6 +144,8 @@ gh_auth() {
GITHUB_TOKEN=$(coder external-auth access-token github)
export GITHUB_TOKEN
fi
elif token="$(gh auth token --hostname github.com 2>/dev/null)"; then
export GITHUB_TOKEN=$token
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏼

Comment on lines +137 to +138
if [[ -z ${GITHUB_TOKEN:-} ]]; then
if [[ -n ${GH_TOKEN:-} ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should always get the new token. The token stored in GITHUB_TOKEN may be stale, so I opted to refresh this even though it's set.

coder external-auth access-token github handles the auto-refreshing automatically.

Copy link
Collaborator

@matifali matifali left a comment

Choose a reason for hiding this comment

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

When inside a coder workspace, We should always get the new token. The token stored in GITHUB_TOKEN may be stale, so I opted to refresh this even though it's set.

@mafredri
Copy link
Member Author

mafredri commented May 8, 2024

When inside a coder workspace, We should always get the new token. The token stored in GITHUB_TOKEN may be stale, so I opted to refresh this even though it's set.

@matifali Why would there be a token stored in GITHUB_TOKEN that's stale, and how would that happen? The reason I made external auth secondary to the env being set is that during yesterdays release we ran into the issue of the Coder external-auth token (i.e. GitHub App) not having all the required permissions, so we had to manually gh auth login and use that token.

@matifali
Copy link
Collaborator

matifali commented May 8, 2024

If someone sets the token manually or inject via coder_env that would stale for sure. But as we have full control over the dogfood template and there is no way the GITHUB_TOKEN can be automatically set so I think it's fine to merge. I am perhaps over thinking.

@matifali matifali self-requested a review May 8, 2024 15:37
@mafredri
Copy link
Member Author

mafredri commented May 8, 2024

If someone sets the token manually or inject via coder_env that would stale for sure. But as we have full control over the dogfood template and there is no way the GITHUB_TOKEN can be automatically set so I think it's fine to merge. I am perhaps over thinking.

@matifali I'm happy you are over-thinking, wouldn't want to break any use-cases. I think the best solution would be to probe the validity of the token, and if it's expired run the path within the if-statement. I think we can leave that for future enhancement, though.

@github-actions github-actions bot added the stale This issue is like stale bread. label May 16, 2024
@stirby
Copy link
Collaborator

stirby commented May 16, 2024

@mafredri, if this resolves all the script issues we encountered, can should merge soon? Colin and I ran through the scripts for patching mainline and would like to do the same for stable tomorrow.

@github-actions github-actions bot removed the stale This issue is like stale bread. label May 17, 2024
@mafredri mafredri enabled auto-merge (squash) May 17, 2024 08:20
@mafredri mafredri merged commit f66d044 into main May 17, 2024
33 checks passed
@mafredri mafredri deleted the mafredri/chore-scripts-fix-release-promote-env branch May 17, 2024 08:25
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants