Giter Club home page Giter Club logo

configure-pages's Introduction

configure-pages

A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as starter workflows.

See set-pages-config.js for more details on how we configure static site generators to work "out of the box" with GitHub Pages.

Usage

See action.yml and the Pages starter workflows.

Release instructions

In order to release a new version of this Action:

  1. Locate the semantic version of the upcoming release (a draft is maintained by the draft-release workflow).

  2. Publish the draft release from the main branch with semantic version as the tag name, with the checkbox to publish to the GitHub Marketplace checked. ☑️

  3. After publishing the release, the release workflow will automatically run to create/update the corresponding the major version tag such as v0.

    ⚠️ Environment approval is required. Check the Release workflow run list.

License

The scripts and documentation in this project are released under the MIT License.

configure-pages's People

Contributors

andrewlester avatar dependabot[bot] avatar github-actions[bot] avatar jamesmgreene avatar jeremy-daley-kr avatar rentziass avatar smithaborkar avatar takost avatar thekojueffect avatar toomanybees avatar wofwca avatar yimysty avatar yoannchaudet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

configure-pages's Issues

Configuration seems to struggle with Next.js PWA configurations

I am working on migrating a web application to Next.js in this repo. However, I am running into an issue where the basePath is seemingly not injected.

My configuration looks like the following:

const withPWA = require("next-pwa")({
	dest: "public",
});

module.exports = withPWA({
	compiler: {
		styledComponents: true,
	},
	reactStrictMode: true,
});

However, the step using the actions/configure-pages action outputs this warning from #43:

Warning: Unsupported configuration file extension. Currently supported extensions: ".js", ".cjs", ".mjs"

Other than the fact that the next.config.js configuration uses the .js extension, it seems that the action fails to inject properties into a configuration wrapped by a higher-order withPWA function. A more useful error is not logged, so this issue is hard to diagnose.

New configure

Thank you 🙇‍♀ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please delete this text and continue to create this issue. Thank you in advance.

The action ignores .ts config and creates default nuxt.config.js

This issue occurs when generator_config_file input is not provided

It may not be obvious when using Nuxt 3 Workflow suggested by Github. Additionally Nuxt 3 uses .js configuration file, even if a .ts config exists which makes it harder to debug this problem

Logs from the Action:

2023-03-03T23:28:19.0111047Z ##[group]Run actions/configure-pages@v3
2023-03-03T23:28:19.0111362Z with:
2023-03-03T23:28:19.0111649Z   static_site_generator: nuxt
2023-03-03T23:28:19.0112072Z   token: ***
2023-03-03T23:28:19.0112376Z   enablement: false
2023-03-03T23:28:19.0112643Z ##[endgroup]
2023-03-03T23:28:19.2606651Z Using default blank configuration
2023-03-03T23:28:19.2607688Z Injecting property=router.base and value=/retejs.org/ in:
2023-03-03T23:28:19.2608390Z // Default Pages configuration for Nuxt
2023-03-03T23:28:19.2608933Z export default {}
2023-03-03T23:28:19.2609265Z 
2023-03-03T23:28:19.2646922Z Found configuration object in direct default export declaration
2023-03-03T23:28:19.2647736Z Injection successful, new configuration:
2023-03-03T23:28:19.2648328Z // Default Pages configuration for Nuxt
2023-03-03T23:28:19.2648910Z export default {router: {base: "/retejs.org/"}}
2023-03-03T23:28:19.2649193Z 
2023-03-03T23:28:19.2649641Z Injecting property=target and value=static in:
2023-03-03T23:28:19.2650266Z // Default Pages configuration for Nuxt
2023-03-03T23:28:19.2651052Z export default {router: {base: "/retejs.org/"}}
2023-03-03T23:28:19.2651341Z 
2023-03-03T23:28:19.2662753Z Found configuration object in direct default export declaration
2023-03-03T23:28:19.2663623Z Injection successful, new configuration:
2023-03-03T23:28:19.2664196Z // Default Pages configuration for Nuxt
2023-03-03T23:28:19.2664771Z export default {target: "static",router: {base: "/retejs.org/"}}
2023-03-03T23:28:19.2665088Z 
2023-03-03T23:28:19.2785735Z ##[group]Run cat ./nuxt.config.ts
2023-03-03T23:28:19.2786080Z �[36;1mcat ./nuxt.config.ts�[0m
2023-03-03T23:28:19.2838925Z shell: /usr/bin/bash -e {0}
2023-03-03T23:28:19.2839234Z env:
2023-03-03T23:28:19.2839520Z   GITHUB_PAGES: true
2023-03-03T23:28:19.2839749Z ##[endgroup]
2023-03-03T23:28:19.2923229Z // https://v3.nuxtjs.org/api/configuration/nuxt.config
2023-03-03T23:28:19.2926664Z export default defineNuxtConfig({
2023-03-03T23:28:19.2926993Z   ssr: true,
2023-03-03T23:28:19.2927254Z   modules: [
......
2023-03-03T23:28:19.2934028Z     langDir: '/locales',
2023-03-03T23:28:19.2934299Z   },
2023-03-03T23:28:19.2934553Z });
2023-03-03T23:28:19.2995970Z ##[group]Run cat ./nuxt.config.js
2023-03-03T23:28:19.2996230Z �[36;1mcat ./nuxt.config.js�[0m
2023-03-03T23:28:19.3044971Z shell: /usr/bin/bash -e {0}
2023-03-03T23:28:19.3045175Z env:
2023-03-03T23:28:19.3045363Z   GITHUB_PAGES: true
2023-03-03T23:28:19.3045559Z ##[endgroup]
2023-03-03T23:28:19.3122664Z // Default Pages configuration for Nuxt
2023-03-03T23:28:19.3126129Z export default {target: "static",router: {base: "/retejs.org/"}}

Error when trying to build for NextJS 12.3

The current injection for the default template causes a failure due to specifying the unoptimized value for images to be wrapped in an experimental block. const nextConfig = {experimental: {images: {unoptimized: true}},basePath: "/test"}

However, as of 12.3 this is no longer necessary and will cause build failure of:

Error: Image Optimization using Next.js' default loader is not compatible with next export.

Workaround is to explicitly set the correct value in the next.config.js. Suggesting to either determine version or allow it to be specified in order to conditionally apply the experimental wrapper.

Source: https://nextjs.org/blog/next-12-3#disable-image-optimization-stable

Add note to include `deployment` as typical trigger when using this action?

I know technically this would be a change to the starter workflows repository, but since I think it only applies when you're using this action, I've created the issue here.

One thing I was wondering about is how to make this action run whenever the baseurl of the GitHub Pages site changed. As far as I can tell, that would happen when 1) GitHub Pages is first enabled, 2) when the repo name changes, or 3) the custom domain field changes. It doesn't seem like there are any workflow triggers that hook into a repo's settings, but there is the deployment trigger, which (as I interpret it, and in my testing) runs after each time the repo's GitHub Pages is deployed (is there any other kind of "deployment"?).

As such, if you're using this action to get the most up to date baseurl, I think you need to run it on the deployment trigger. Unfortunately this means that if you're making a commit based off of the change -- e.g. updating baseurl in _config.yaml -- then pages will build once, then run this action, then make the commit which will make pages build again. So you get duplicate builds, but I don't see a way around it unless GitHub adds more triggers.

Anyway, maybe you could add a note about using this trigger to the readme here?

Or maybe there's a better way that I don't know of?

Supported configuration file extension check does not use the per-generator default

The setPagesConfig function uses different error messages depending on whether the generator configuration file has a correct extension. However, the configuration file used for this check is based on the context generator_config_file input only, rather than the default configuration file for the generator used that is computed by the getConfigParserSettings function.

As a result, if generator_config_file is not specified, then errors within the setPagesConfig function will always be blamed on an incorrect file extension.

Support for specifying folder

My next project is in a monorepo, and therefore the next.config.js isn't on root.

An input so I could specify the working directory would solve this for me.

Default configuration for next js needs to be updated

I think the change from the command 'next export' to "output: export" in next.config.js has broken the default configuration

this doesnt work

      - name: Setup Pages
        uses: actions/configure-pages@v3
        with:
               static_site_generator: next

this does

      - name: Setup Pages
        uses: actions/configure-pages@v3

I have set up my own next config.

I spent some time trying to find out what was breaking my page so I thought I would pass this on so someone else doesnt have to

Proxy issues when using self-hosted runners

I've run into issues with this action and the deploy-pages action because they don't seem to support proxies in self-hosted runners. It's not a 404, rather a 400:

image

Please consider this PR: #63
It uses the @actions/github API instead of manually constructing the axios requests. Whatever their package is doing behind the scenes fixes the self-hosted runner issue I'm having... and honestly just makes more sense in my opinion.

Add support for generating `preview: true` deployment environment URLs? 🧪

Tangentially for the 🧪 experimental-alpha-internal-only support that actions/deploy-pages offers for Pages preview deployments per PR 🧪, it would be great if this action could also generate the expected URL for that forthcoming deployment as well earlier in the Actions workflow run so that it could be passed in to the site's build process.

Need to do some more investigation on if the URL that will be generated is consistently predictable. 🤔

Set `$BASE_URL` or similar env var for subsequent steps

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. 🤷‍♀️

Pages config is not injected when generators using with typescript

Pages config is not injected when using gatsby-config.ts.
Gatsby will ignore pathPrefix and build the site as if hosted from the root domain.

To Reproduce

  1. Create Gatsby Project with TypeScript
  2. Add deploy action from template
  3. Run Workflow

Run actions/configure-pages@v2

Using default blank configuration
Injecting property=pathPrefix and value=/temp-gatsby-starter-ts/ in:
// Default Pages configuration for Gatsby
module.exports = {}

Found configuration object in direct module export
Injection successful, new configuration:
// Default Pages configuration for Gatsby
module.exports = {pathPrefix: "/temp-gatsby-starter-ts/"}

Injecting property=siteMetadata.siteUrl and value=https://bicstone.github.io/ in:
// Default Pages configuration for Gatsby
module.exports = {pathPrefix: "/temp-gatsby-starter-ts/"}

Found configuration object in direct module export
Injection successful, new configuration:
// Default Pages configuration for Gatsby
module.exports = {siteMetadata: {siteUrl: "https://bicstone.github.io/"},pathPrefix: "/temp-gatsby-starter-ts/"}

Gatsby will ignore pathPrefix and build the site as if hosted from the root domain

https://bicstone.github.io/temp-gatsby-starter-ts/

thank u

Thank you 🙇‍♀ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please delete this text and continue to create this issue. Thank you in advance.

[Next.js] basePath should be / when using a custom URL

When configuring a custom domain for a repository, the basePath for a Next.js app should not include the name of the repo as the root of the website is just /.

Steps to reproduce

  • Configure a custom URL for a repo in Settings > Pages > Custom Domain
  • Deploy the next-app using actions/configure-pages@v3
  • See that none of the resources (like CSS or JS) can be loaded as the basePath is set to reponame

Workaround

To still keep the "disable image optimisation"-option, I forked this action and removed the basePath config, but that is not optimal.

Suggestion

  • Make the basePath configurable and when nothing is configured, it's using the reponame, but a user could overwrite it with / if they want to
  • Update the comment in the provided workflow (nextjs.yml) to make sure that user know that this can be done (but I guess this is not the scope of this repo, pease let me know where this should be fixed)

Doesn't recognize next.config.mjs

It works fine with the js extension:

Run actions/configure-pages@v3
  with:
    static_site_generator: next
Injecting property=basePath and value= in:
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export",
};

...but when I have a next.config.mjs, it ignores it and makes up a new config file on its own:

Run actions/configure-pages@v3
  with:
    static_site_generator: next
Using default blank configuration
Injecting property=basePath and value= in:
// Default Pages configuration for Next
const nextConfig = {}
module.exports = nextConfig

PRUEBA

Thank you 🙇‍♀ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please delete this text and continue to create this issue. Thank you in advance.

Create Pages site failed: Resource not accessible by integration

Related: actions/starter-workflows#332

The repo's actions permissions are already set to read and write by default. Also tried setting permissions: write-all on the job. Also tried triggering on push, which I could've sworn was working yesterday. Nothing is working today.

name: Perform first-time setup of repo

on: create

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
      - name: Enable GitHub Pages
        uses: actions/configure-pages@v2
Run actions/configure-pages@v2
  with:
    token: ***
    enablement: true
  
Warning: Get Pages site failed
Error: Create Pages site failed
Error: AxiosError: Request failed with status code 40[3]

I also tried enabling Pages more directly with the GitHub API, and still got an error:

name: Perform first-time setup of repo

on: create

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
      - name: Enable GitHub Pages
        id: url
        uses: actions/github-script@v6
        with:
          script: |
            return (await github.rest.repos.createPagesSite({
              owner: context.repo.owner,
              repo: context.repo.repo,
            })).html_url;
with:
    script: return (await github.rest.repos.createPagesSite({
    owner: context.repo.owner,
    repo: context.repo.repo,
    build_type: "legacy",
  })).html_url;
  
    github-token: ***
    debug: false
    user-agent: actions/github-script
    result-encoding: json
    retries: 0
    retry-exempt-status-codes: 400,401,40[3](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:3),[4](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:4)04,422
RequestError [HttpError]: Resource not accessible by integration
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:6172:21
Error: Unhandled error: HttpError: Resource not accessible by integration
    at processTicksAndRejections (node:internal/process/task_queues:96:[5](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:5))
    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v[6](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:6)/dist/index.js:13356:16), <anonymous>:3:9)
    at async main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13452:20) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/vincerubinetti/lab-website-template/pages',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      connection: 'close',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Wed, 23 Nov 2022 02:55:23 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-media-type': 'github.v3',
      'x-github-request-id': '0402:0C51:2[7](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:7)629CE:507BEC5:637D[8](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:8)B[9](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:9)B',
      'x-ratelimit-limit': '[10](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:10)00',
      'x-ratelimit-remaining': '999',
      'x-ratelimit-reset': '1669175723',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '1',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Resource not accessible by integration',
      documentation_url: 'https://docs.github.com/rest/pages#create-a-github-pages-site'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/vincerubinetti/lab-website-template/pages',
    headers: {
      accept: 'application/vnd.github.-preview+json',
      'user-agent': 'actions/github-script octokit-core.js/3.6.0 Node.js/16.[13](https://github.com/vincerubinetti/lab-website-template/actions/runs/3528824640/jobs/5919310323#step:2:13).0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"build_type":"legacy"}',
    request: { agent: [Agent], hook: [Function: bound bound register] }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.