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

Set $BASE_URL or similar env var for subsequent steps #105

Closed
jcbhmr opened this issue Sep 26, 2023 · 2 comments
Closed

Set $BASE_URL or similar env var for subsequent steps #105

jcbhmr opened this issue Sep 26, 2023 · 2 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@jcbhmr
Copy link

jcbhmr commented Sep 26, 2023

It's my understanding that this action is sort of an optional configuration step in the chain of:

  • actions/configure-pages
  • (build your site)
  • actions/upload-pages-artifact
  • actions/deploy-pages

Where actions/configure-pages is supposed to tweak some configs a bit like for Next.js to make it play nice with a https://example.org/sub-project/... base URL.

Since that seems to be the goal, I'd like to propose a feature: auto-setting some kind of $PAGES_BASE_URL or $BASE_URL (idk if there's a common conventional name or standard) or some other environment variable like this:

await appendFile(process.env.GITHUB_ENV, `BASE_URL=${baseURL}`)
// or similar

Why is this a good idea? 1) It's an environment variable, not an output. That means you don't need to do this messiness each time you want to use it:

- id: my-id
  uses: actions/configure-pages@vN
- run: npm run build:docs
  env:
    BASE_URL: ${{ steps.my-id.outputs.base_url }}/

2) It makes it much easier for non-Next.js/Jekyll/whatever supported projects in the magic js file to just pick up on a $BASE_URL env var. Yes, you can do this now but it's a bit clunky with adding the outputs to an env var manually.

This proposed $BASE_URL idea is more implicit than the current explicit ${{ steps.my-id.outputs.base_url }} is right now. In my opinion that's OK similar to how there's already a slew of $GITHUB_* env vars but my opinion isn't the right answer.

If this is out-of-scope, feel free to close this. This is just a QoL feature that would make it easier to do configs without mucking with outputs in my-pages-workflow.yml. 🤷‍♀️

@jcbhmr
Copy link
Author

jcbhmr commented Sep 26, 2023

This would also be a way around issues like #74 so that you can just do something like this in your config as opposed to wrangling with manually computing process.env.GITHUB_REPOSITORY.split("/")[1] and handling if (process.env.GITHUB_REPOSITORY.split("/")[1].endsWith(".github.io")) ... edge cases

// https://nextjs.org/docs/pages/api-reference/next-config-js
module.exports = {
  ...process.env.BASE_URL && { basePath: new URL(process.env.BASE_URL).pathname },
}
- uses: actions/configure-pages@vN
- run: npm run build:docs # gets the BASE_URL env var from configure-pages

@jcbhmr jcbhmr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@JamesMGreene JamesMGreene added the wontfix This will not be worked on label Nov 23, 2023
@JamesMGreene JamesMGreene self-assigned this Nov 23, 2023
@JamesMGreene
Copy link
Contributor

BASE_URL is a far too generic environment variable name for GitHub Pages to lay claim to. If we were going to do something like this, it would be very explicitly named, like GITHUB_PAGES_BASE_URL.

As it is, I would still suggest utilizing the action's outputs.base_url to set the value of the relevant environment variable for your own usage as outlined in your original post. 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants