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

Save Wrangler Command Output to a Variable #213

Merged
merged 16 commits into from
Dec 13, 2023

Conversation

GrantBirki
Copy link
Contributor

@GrantBirki GrantBirki commented Dec 1, 2023

Save Wrangler Command Output to a Variable

Please disregard the branch name, I changed what this PR does per @1000hz's suggestions

This pull request enables a more advanced usage of this Action in conjunction with other workflow steps. These changes allow users to gain the ability to parse the wrangler command's output in subsequent workflow steps should they need to.

The @actions/exec package is utilized to save the stdout and stderr streams to variables and then those variables are written to two new Actions outputs when this job completes. These two new outputs are as follows:

  • command-output: contains the string results of stdout
  • command-stderr: contains the string results of stderr

But wait, there is more! ⭐

Since we are saving the stdout to a variable, it can now be parsed by this Action just a little bit more before exiting. I added in a bonus feature to this PR to detect if the command being run is a deployment for a Cloudflare Pages site or Worker. If it is a deployment, then the deployment-url output gets populated.

  • deployment-url: contains the string results of the URL that was deploy (ex: https://<your_pages_site>.pages.dev)

Why?

I personally have several open source projects which I help maintain. We use this Action to deploy our Cloudflare Pages sites. Recently, our workflows for dev environments started breaking. This was a direct result of #210

Here is a resulting Action's log of the failure

This is because we are trying to save the stdout of this Action by piping it to a file. This isn't really the best solution but it worked... at least for a while before it broke. This PR will prevent us from having to use choppy command line hacks in the future.

Being able to capture the output of this command to get the unique dev environment URL for pages deployments is required by our workflows to use it in subsequent workflow steps. This pull request also solves that problem via the new deployment-url output that gets saved as well.

Example 📸

image

live example workflow -> https://github.com/the-hideout/tarkov-dev/actions/runs/7064233377/job/19231836343


resolves: #211

Thanks! ⭐

@GrantBirki GrantBirki requested a review from a team as a code owner December 1, 2023 18:19
@1000hz
Copy link
Contributor

1000hz commented Dec 6, 2023

Hey @GrantBirki, thanks for the PR. Would your use case be satisfied if we implemented the command-output action output as described in #211?

@GrantBirki
Copy link
Contributor Author

@1000hz that would be even better! Do you mind if I alter this PR to make all the text that gets written to a file be written to the command-output output instead?

@1000hz
Copy link
Contributor

1000hz commented Dec 7, 2023

@GrantBirki that'd be wonderful. Thanks!

@GrantBirki GrantBirki changed the title Optionally Save Wrangler Command Output to a File 📁 Save Wrangler Command Output to a Variable Dec 8, 2023
@GrantBirki
Copy link
Contributor Author

@1000hz I have good news, this is ready for review! 🎉

I have tested that all code included in this pull request works:

I managed to fully implement the command-output that you suggested but also with a few bonuses! I also added a command-stderr variable for users to dig into specific error messages that wrangler commands may return in subsequent workflow steps. I also managed to add the deployment-url output that you mentioned in the other issue as well.

Let me know if you have any questions. Thanks!

Copy link
Contributor

@1000hz 1000hz left a comment

Choose a reason for hiding this comment

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

Nice work, @GrantBirki! Left a few comments.

package.json Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
action.yml Outdated Show resolved Hide resolved
Co-authored-by: Cina Saffary <[email protected]>
src/index.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
.changeset/plenty-seals-cover.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@1000hz 1000hz merged commit 0e62aca into cloudflare:main Dec 13, 2023
2 of 3 checks passed
@1000hz
Copy link
Contributor

1000hz commented Dec 13, 2023

Thanks for the contribution, @GrantBirki!

@github-actions github-actions bot mentioned this pull request Dec 13, 2023
@GrantBirki
Copy link
Contributor Author

Thank you! 🎉

@GrantBirki GrantBirki deleted the write-results-to-a-file branch December 13, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add outputs to action
4 participants