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: avoid erroring if conflicting techniques are set from environment variables #374

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

zimeg
Copy link
Member

@zimeg zimeg commented Dec 5, 2024

Summary

This PR allows both environment variables SLACK_TOKEN and SLACK_WEBHOOK_URL to exist in a workflow without causing steps to error due to an undefined technique! Fixes #373.

Reviewers

Add the following to the workflow in develop.yml before running with npm run dev:

+   env:
+     SLACK_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
    runs-on: ubuntu-latest

This should error before the change is applied but not after!

Requirements

@zimeg zimeg added bug Something isn't working semver:patch labels Dec 5, 2024
@zimeg zimeg added this to the 2.1 milestone Dec 5, 2024
@zimeg zimeg requested review from seratch and a team December 5, 2024 04:15
@zimeg zimeg self-assigned this Dec 5, 2024
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

I haven't verified the behavior but the code changes look good to me and there is nothing to suggest so far. This is pretty cool!

Copy link
Member Author

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@seratch Thank you once again for such a fast review! I'll test this a few more times before merging, but will merge once things are feeling good.

Also leaving a few notes on some of the stranger changes, but am hopeful that tests cover the expected behaviors well 🙏

);
core.setSecret(this.inputs.token);
core.setSecret(this.inputs.webhook);
case !!core.getInput("token") && !!core.getInput("webhook"):
Copy link
Member Author

Choose a reason for hiding this comment

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

This prevents adding both token and webhook as inputs using with while still allowing both environment variables!

Comment on lines +157 to +158
case !!this.inputs.method:
if (!this.inputs.token) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Special care was taken in flipping these cases with wording since we can't assume a set this.inputs.token means that technique is being used.

Instead, I think we must check for a method instead of token, and always check method before webhook 🤔

@@ -29,7 +29,7 @@ export default async function send(core) {
*/
async function post(config) {
switch (true) {
case !!config.inputs.token:
case !!config.inputs.method:
Copy link
Member Author

Choose a reason for hiding this comment

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

IMO an important change that might've been missed without testing a bit! Before changes, an environment variable might've set this and caused this case to run despite possible inputs preferring the webhook.

This is covered and confirmed in the send.spec.js tests!

@zimeg
Copy link
Member Author

zimeg commented Dec 5, 2024

🚢 💨 Merging now! But going to hold off on an immediate release with hopes of landing a few docs updates before the next tag. Planning to make those changes soon in another PR- 🫡

@zimeg zimeg merged commit 4879c43 into main Dec 5, 2024
3 checks passed
@zimeg zimeg deleted the zimeg-fix-shared-technique-environment branch December 5, 2024 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working semver:patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shared environment variables can cause multiple techniques to match which errors
2 participants