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

Workflows for automated releases and github-pages builds #3137

Merged
merged 43 commits into from
Jan 26, 2024
Merged

Workflows for automated releases and github-pages builds #3137

merged 43 commits into from
Jan 26, 2024

Conversation

alexcottner
Copy link
Contributor

@alexcottner alexcottner commented Jan 22, 2024

Example links

GitHub Pages Deployment
This will happen automatically upon release publish, or manually whenever a user wants to create a demo build for user acceptance testing. Added notes in readme.md for fork repo configuration and notes on the actions.

Automatic Release Creation on Tags
When a tag is created that matches the v{major}.{minor}.{build} pattern, this workflow will:

  1. Create a new release draft if a release doesn't already exist. This does not fill out any release notes.
  2. Build and publish a single-server build on the release that kinto CD pipelines or users can download

Open Questions

  1. Is creating a draft release for us to fill out good enough? Or do we want to try and prefill some release notes content?

Misc
Commits will be squashed on merge to make this clean.

@alexcottner alexcottner changed the title Working on github pages workflow Workflows for automated releases and github-pages builds Jan 23, 2024
@alexcottner alexcottner marked this pull request as ready for review January 23, 2024 17:50
Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

This workflow differs slightly from what we have in other repos:

  1. Create a release on Github on https://github.com/Kinto/kinto-admin/releases/new
  2. Create a new tag vX.Y.Z (This tag will be created from the target when you publish this release.)
  3. Generate release notes
  4. Publish release

If possible it would be better to align it with the rest. As far as I understand, it only means making sure the release.yml workflow does not try to create the release when it already exists, and would just add attachments.

Also, I think we may want to deploy official versions on Github pages automatically.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated
5. Publish the release when ready

## Deploying to github-pages
A github workflow is included that will release to github pages for any user acceptence testing you may want to do. You must enable github pages first and allow deployment from github actions (Settings > Pages).
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to deploy to Github pages automatically on tags?

You must enable github pages first and allow deployment from github actions

What does it mean? Approve deployments?

README.md Outdated
## Deploying to github-pages
A github workflow is included that will release to github pages for any user acceptence testing you may want to do. You must enable github pages first and allow deployment from github actions (Settings > Pages).

By default, most branches are restricted from deploying. Additional branches can be allowed to deploy (or any can be allowed) under Settings > Environments > github-pages.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be clearer with two parts:

  • automated deployment on release (along with the releasing info)
  • how to deploy custom branch on gh-pages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to make all of this a little clearer. Will read it again tomorrow to see if it still makes sense though.

.github/workflows/gh-page.yml Outdated Show resolved Hide resolved
.github/workflows/gh-page.yml Outdated Show resolved Hide resolved
.github/workflows/release.yml Outdated Show resolved Hide resolved
@alexcottner
Copy link
Contributor Author

Also, I think we may want to deploy official versions on Github pages automatically.

Seems like there are two easy ways to make that happen, which sounds better to you?

  1. Kick off gh-pages.yml after release.yml runs
  2. Have gh-pages.yml also listen for tag creation

@grahamalama
Copy link
Contributor

grahamalama commented Jan 25, 2024

Have gh-pages.yml also listen for tag creation

I vote this one 👍🏻

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

Seems like there are two easy ways to make that happen, which sounds better to you?

  1. Kick off gh-pages.yml after release.yml runs
  2. Have gh-pages.yml also listen for tag creation

I would vote for 2. But no strong opinion.

Comment on lines 31 to 32
cd build
tar -cvf "$RUNNER_TEMP/kinto-admin-release.tar" *
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
cd build
tar -cvf "$RUNNER_TEMP/kinto-admin-release.tar" *
tar -cvf --cd build/ "$RUNNER_TEMP/kinto-admin-release.tar" *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have --cd as a valid option on my machine or on the ubuntu 22.04 docker container I just pulled. And I don't see it in the manual. Is this some non-standard thing or am I totally overlooking it?

Copy link
Contributor

Choose a reason for hiding this comment

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

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
2. Under "Build and deployment" choose Source > GitHub Actions
2. Choose which branches should be allowed to deploy to pages
1. Go Settings > Environments > Github Pages
2. Under "Deployment branches and tags", configure which branches should be allowed to deploy to pages
Copy link
Contributor

Choose a reason for hiding this comment

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

There's something that I find unclear in these instructions...
Are they meant to be ran each time? Are they targeted at contributors/forks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to make that clearer

2. Select the "Deploy to Github Pages" action
3. Select "Run workflow" and choose the branch you wish to build against
4. Click "Run workflow"
5. Kinto-admin will be deployed to `https://{owner}.github.io/kinto-admin`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why {owner} here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{owner} is the syntax I've seen in the github docs. So the for kinto's repo this would be https://kinto.github.io/kinto-admin, but for my fork it's https://alexcottner.github.io/kinto-admin/ . Is there a way to make this clearer?

@alexcottner
Copy link
Contributor Author

gh-pages workflow listens for release publishes and will publish a build to pages automatically.
Updated readme to be clearer

2. When tagging your release, enter a standard version number like `vX.Y.Z`
3. After the release is published (including pre-release), built assets will be attached as files, including:
1. Source code based on the tagged commit
2. A single-server build for kinto-admin in a tar file (this may take a few minutes to show up)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
2. A single-server build for kinto-admin in a tar file (this may take a few minutes to show up)
2. A single-server build meant to be used in a `kinto` installation in a tar file (this may take a few minutes to show up)

Do you think we should explicitly mention that we're setting ASSET_PATH and SINGLE_SERVER?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Being verbose can't hurt. Will add.

Comment on lines 23 to 26
LATEST_TAG=$(echo $GITHUB_REF | sed s/^v// | tr -d '"')
VERSION_NUMBER=".version=\"${LATEST_TAG}\""
jq ${VERSION_NUMBER} package.json > temp_package.json
mv temp_package.json package.json
Copy link
Contributor

Choose a reason for hiding this comment

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

One issue with doing this only in CI is that if people build Kinto Admin the "old" way to customize build variables (that is, curl the source code then run npm run build), the version won't be overwritten.

What if we handled this in vite.config.ts instead? Here's a quick example that only gets the latest tag, but perhaps we could write a function that encompases all of the logic currently in the action workflow:

diff --git a/vite.config.ts b/vite.config.ts
index 9817bd7..f2d2111 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -2,6 +2,8 @@
 
 import { defineConfig } from 'vite'
 import react from '@vitejs/plugin-react'
+import { execSync } from 'child_process'
+
 /**
  * used to set the relative path from which we expect to serve the admin's
  * static bundle on the server:
@@ -9,7 +11,7 @@ import react from '@vitejs/plugin-react'
  *    Kinto plugin: /v1/admin/
  */
 const ASSET_PATH = process.env.ASSET_PATH || "/";
-
+const KINTO_ADMIN_VERSION = execSync('git describe --tags --abbrev=0').toString()
 // https://vitejs.dev/config/
 export default defineConfig({
   server: {
@@ -19,7 +21,7 @@ export default defineConfig({
   plugins: [react()],
   base: ASSET_PATH,  
   define: {
-    KINTO_ADMIN_VERSION: JSON.stringify(process.env.npm_package_version),
+    KINTO_ADMIN_VERSION: JSON.stringify(KINTO_ADMIN_VERSION)
   },
   build: {
     outDir: "build"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do like that this simplifies things. I'll combine this with @leplatrem 's suggestion above to do a --abbrev=4. If they're exactly on a tag, it'll just be the tag name returned. If they're beyond that tag, it'll note how far ahead they are and which sha they're on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented!

Comment on lines 30 to 35
- name: Create release
uses: softprops/action-gh-release@v1
with:
draft: true
fail_on_unmatched_files: true
files: ${{ runner.temp }}/kinto-admin-release.tar
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it works just fine, so consider this comment optional, but it might be nice if we don't have to rely on a 3rd party action for this. It looks like the gh CLI has a release command built in -- maybe that'd work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I settled on this one after finding actions/create-release being archived/unsupported and it's read-me mentioning this one and it seeming simple enough for our needs.

I'll look into the cli option to see what that takes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented!

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

💯 The ghpages section in the docs is a lot clearer with these titles , thanks for your patience 🙏

Copy link
Contributor

@grahamalama grahamalama left a comment

Choose a reason for hiding this comment

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

Looks good! Does this also mean we can rip out the publish-to-gh-pages command and gh-pages dependency?

@alexcottner
Copy link
Contributor Author

Does this also mean we can rip out the publish-to-gh-pages command and gh-pages dependency?

Oh yes, I'll do that. I forgot to remove those because my plan A was to use them, but that didn't work out.

@alexcottner alexcottner merged commit 2d2b28b into Kinto:master Jan 26, 2024
6 checks passed
@alexcottner alexcottner deleted the github-build branch January 26, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants