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(ci): setup auto docs publish workflow for release vX.X.X tag #7331

Conversation

ShenQingchuan
Copy link
Member

Automatic workflow for release docs publish

I wrote these guides in order to give our reviewers more context and information here.

Why for this PR ?

After publishing a new release of Vite, we must open Netlify UI to trigger docs build & publish manually now.

It's because the contents of docs folder are actively updating, and we'll always see the latest content on docs site if we use Netlify's git-based deployment, but actually there's something ahead of current release.

So I'm wondering if there's some ways for setting up an automatically deploy workflow which only targets on vX.X.X tag, it's a significant sign.

Is these changes enough ?

Actually, NO. we should add more configs around.

First: turn off Netlify builds

Since now this repo would not trigger a new deploy by commit pushing, we can skip this step if it's already done.

  1. Go to Netlify UI, site administration page.
  2. Open Site Setting panel
  3. Open Build & Deploy tab on the left side
  4. Scroll down to Build Settings, and click Edit Settings
  5. Select Builds --> Stop Builds

Second: setting up secrets

This step may requires @yyx990803, @patak-dev or someone has right to access this repo's setting panel, to create a list of following fields:

  1. VITE_GITHUB_TOKEN: this is a Github Access Token, may need to be generated by manually creating @yyx990803

    https://github.com/settings/tokens

  2. NETLIFY_AUTH_TOKEN: this is a personal access token which is supposed to be generate on Netlify.

    https://app.netlify.com/user/applications#personal-access-tokens

  3. NETLIFY_SITE_ID: this one could be found at General | Site settings

    But I could use an open API of Netlify to query for result:

curl https://api.netlify.com/api/v1/sites/vitejs.dev

// id: 8c66140b-3a31-475e-b0c6-ff6689563820

image

That's all for configuration.

@ShenQingchuan ShenQingchuan force-pushed the shenqingchuan/netlify-deploy-by-api branch 2 times, most recently from 374bcca to faf559b Compare March 15, 2022 17:15
@patak-dev patak-dev self-assigned this Mar 18, 2022
@patak-dev
Copy link
Member

@ShenQingchuan in Vitest we have a setup that shows a preview for each commit that affects the docs: vitest-dev/vitest#970. Would the action you used here do the same? @antfu do you have a link to guide us to do the same you did for Vitest here?

@antfu
Copy link
Member

antfu commented Mar 20, 2022

a link to guide

Actually, it's the default behavior of Netlify - unless you disable it explicitly. I guess it's done by Evan for a reason 👀

@patak-dev
Copy link
Member

Added for discussion in the next meeting, let's check with him then.

@ShenQingchuan
Copy link
Member Author

ShenQingchuan commented Mar 20, 2022

@ShenQingchuan in Vitest we have a setup that shows a preview for each commit that affects the docs: vitest-dev/vitest#970. Would the action you used here do the same? @antfu do you have a link to guide us to do the same you did for Vitest here?

No, the setup I made here is for release docs publish.
I know that maybe you @patak-dev also want to keep the preview feature of Netlify and not trigger a production release in daily commits pushing. I'll find it out how to do it !

Could you please let me sit in on the next internal meeting when talking about this issue ( for only once 😊 )

@ShenQingchuan ShenQingchuan force-pushed the shenqingchuan/netlify-deploy-by-api branch from faf559b to 419b18e Compare March 20, 2022 17:03
@ShenQingchuan
Copy link
Member Author

ShenQingchuan commented Mar 20, 2022

2nd Update

What's new? I've removed the config field production-branch: main because it would send production build request on Netlify by default ( even with production-deploy is actually false by default ). So we can only use production-deploy with an expression value instead.

production-deploy: ${{ github.event_name == 'release' }}

It would generate "Preview" deploy as expected when we modified and pushed anything under docs/.

References for your need:

@ShenQingchuan
Copy link
Member Author

And I'm supposed to provide some more information...

the "Preview Build" is indeed a feature of Netlify but it's not by default, it depends on which branch you assign as a "Production branch"

  • if you push something to the "Production branch", it triggers a "Production build"
  • if you push something to another branch, it triggers a "Preview build"

@patak-dev
Copy link
Member

Sorry for taking so much time @ShenQingchuan, v2.9 is out now, so getting back to this.

Some questions:

  1. So IIUC, we aren't trying to get netlify to send as the docs previews. I checked in Vitest, and we are getting them even if we don't touch the docs and that is quite noisy: fix: vitest cannot read the latest config when it changes vitest-dev/vitest#1001.

  2. If we delete the netlify.toml file, aren't we going to stop being able to use the Netlify UI? For example the Retry Deploy. It may still be ok, we haven't used that button until now.

  3. About VITE_GITHUB_TOKEN, could we directly use secrets.GITHUB_TOKEN that is automatically generated for the action?

  4. The current workflow will also deploy the docs for production when we release a plugin. Until now, we are only publishing when releasing Vite core. There have been some times when we released a plugin in the middle of a beta for example. So we should check that the tag of the release corresponds to Vite. We should also avoid releasing for production for a beta release. (unrelated, but I think it would be great to have a public https://beta.vitejs.dev deployment for the betas)

@patak-dev patak-dev added the p1-chore Doesn't change code behavior (priority) label Apr 1, 2022
@ShenQingchuan
Copy link
Member Author

ShenQingchuan commented Apr 6, 2022

Sorry for taking so much time @ShenQingchuan, v2.9 is out now, so getting back to this.

Some questions:

  1. So IIUC, we aren't trying to get netlify to send as the docs previews. I checked in Vitest, and we are getting them even if we don't touch the docs and that is quite noisy: fix: vitest cannot read the latest config when it changes vitest-dev/vitest#1001.
  2. If we delete the netlify.toml file, aren't we going to stop being able to use the Netlify UI? For example the Retry Deploy. It may still be ok, we haven't used that button until now.
  3. About VITE_GITHUB_TOKEN, could we directly use secrets.GITHUB_TOKEN that is automatically generated for the action?
  4. The current workflow will also deploy the docs for production when we release a plugin. Until now, we are only publishing when releasing Vite core. There have been some times when we released a plugin in the middle of a beta for example. So we should check that the tag of the release corresponds to Vite. We should also avoid releasing for production for a beta release. (unrelated, but I think it would be great to have a public https://beta.vitejs.dev deployment for the betas)

Hi, @patak-dev

Sorry for take so long to notify that this issue got an update! I would like to answer your questions one by one:

  1. Sorry for that I don't really get your point at this one, do you mean that we're not going to set a Netlify preview every commit because that's annoying? IIUC, then my answer is "That's ok", now this PR set up "Preview build" only for every changes under docs/ dir.

  2. Yes for "Not able to use the 'Re-trigger build' button in Netlify Admin UI", but it's not because of netlify.toml deletion, it's because we need to stop(de-activate) "Netlify Build", this setting will effect whether turn to an auto build for each commit in this repo. We actually need to get full control of build to implement our specific "logic" about publishing docs.

    Difference between "Stop build" & "Stop auto publishing":
    According to my Q&A with Evan and my own experiment:

    • Stop auto publishing(Now this repo is using this one): build on every commit, but no publish, need manually click "Publish Deploy" button in Netlify UI.
    • Stop build: Netlify will not trigger build by any commit / PR or something else, can only send deploy via API

    So I think we may not need Netlify UI anymore as we just use this platform to deploy, and the Github Action plugin nwtgck/actions-netlify could meet our needs.

  3. I don't know about this feature. Does every action task generate its own Github token?

  4. OK, I got your point. I will think about how to change the setting to match our needs. The main difficulty is how to write a correct "conditional expression" in Github Workflow Configuration for publish-deploy field.

@ShenQingchuan
Copy link
Member Author

For the question 4: I may need to get it more clear ...

Do we just need to publish docs on vX.X.X tags release ? @patak-dev

only trigger production build for core release
@patak-dev
Copy link
Member

patak-dev commented Apr 6, 2022

. 4. Yes, only for vX.X.X

. 3. Yes, and it is available as secrets.GITHUB_TOKEN https://docs.github.com/en/actions/security-guides/automatic-token-authentication

. 1. and 2. I was only checking that I understood the implications and I agree that what you are proposing is good 👍

@ShenQingchuan
Copy link
Member Author

@yyx990803

According to my experiment now, we must enable "auto publishing", otherwise the new deploy generated by Github Action can't be the latest "Production build".

with:
publish-dir: "docs/.vitepress/dist"
github-token: ${{ secrets.GITHUB_TOKEN }}
production-deploy: ${{ startsWith(github.ref, 'refs/tags/v') }}
Copy link
Member

Choose a reason for hiding this comment

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

This will also match for beta releases, no? That we wanted to avoid
https://github.com/vitejs/vite/releases/tag/v2.9.0-beta.11

Copy link
Member Author

Choose a reason for hiding this comment

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

yes,maybe a more specific regular expression ..

Copy link
Member Author

Choose a reason for hiding this comment

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

@patak-dev Maybe a clearer definition of our requirements about branch/tag name ?

  • Starts with "v"
  • Not contains "beta" (or something else ?)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, starts with v and not includes beta covers 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.

I use contains which is defined as built-in function @patak-dev

( docs: https://docs.github.com/en/actions/learn-github-actions/expressions#contains )

@patak-dev
Copy link
Member

patak-dev commented Apr 14, 2022

@ShenQingchuan I just saw that netlify auto-deploys now has a fixed URL for main:

This is great, as we can use it to check the current HEAD state and as temporal docs during the beta. Maybe we should check that this PR isn't going to disable this feature, or improve on it by directly deploying on every commit to main.vitejs.dev?

@ShenQingchuan
Copy link
Member Author

@patak-dev

Yes, that's another awesome feature of Netlify that I didn't know !

Does it means that: Right now we already have a url to preview our latest docs ?

@patak-dev
Copy link
Member

Yes, check https://main--vitejs.netlify.app/! 🙌🏼
The UI for netlify changed a bit and now I saw this URL instead of the usual preview one. Or maybe someone touched some general configuration in the Vue netlify account 🤔

@ShenQingchuan
Copy link
Member Author

ShenQingchuan commented Apr 14, 2022

@patak-dev

I found specification about it in Netlify docs, but it seems need to require auto build from a branch. but for main branch, it's quite spacial because it's actually our production branch. And it leads to update our release site by every commit.

But I've got your idea about main.vitejs.dev, I'd think about how to make it work.

@ShenQingchuan
Copy link
Member Author

ShenQingchuan commented Apr 25, 2022

@patak-dev Maybe we can merge this PR first ?

I haven't found any good idea to "Enable auto publishing main branch to main--vitejs.netlify.app" and "Do not auto publishing main branch's deploy as production site content" at the same time, it seems that Netlify do not support this requirement.

This is also important:

According to my experiment now, we must enable "auto publishing", otherwise the new deploy generated by Github Action can't be (published as) the latest "Production build".

@patak-dev
Copy link
Member

I think we are close to moving forward to test it. I found another issue though. We release patches from prev minors so if we tag 2.9.3 -> 2.8.7, we'll end up with stale docs because it will trigger a new deployment. So we need to check that the tag is from the main branch? Or maybe I'm missing something 🤔

@ShenQingchuan another thing that we should think about is how we could deploy to deploy a
v2.vitejs.dev to keep the v2 branch once we start using vitejs.dev for the next major. Maybe it doesn't need to be automatic and we can run the publish command manually from the v2.9.x branch

@patak-dev
Copy link
Member

@antfu is using https://docs.netlify.com/domains-https/custom-domains/multiple-domains/#branch-subdomains for VueUse, so there is deploy with the last version for each major: https://v6-7-6.vueuse.org/. In Vite it is usual to apply patches to older versions, so it would be better to have a https://v2.vitejs.dev. Maybe we could still use it and for the last minor in each major we tag it as v2

@bluwy
Copy link
Member

bluwy commented May 18, 2024

Do we still want to go ahead with this? I believe we have disabled auto publishing, but we still manually trigger publishing when we cut a release, and this PR automates it?

@ShenQingchuan
Copy link
Member Author

I think the problem this PR tried to resolve is staled, so it's closable now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-chore Doesn't change code behavior (priority)
Projects
Status: Discussing
Development

Successfully merging this pull request may close these issues.

None yet

4 participants