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

Auto publish docs for the next branch when there are changes #554

Merged
merged 21 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/publish-docs-next.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Exit on first error, treat unset variables as errors
set -eu

BRANCH_NEXT="next"
BRANCH_GH_PAGES="gh-pages"

echo "BRANCH_NEXT: $BRANCH_NEXT"
echo "BRANCH_GH_PAGES: $BRANCH_GH_PAGES"

# Exit if the current branch is not the next branch
if [[ $(git rev-parse --abbrev-ref HEAD) != "$BRANCH_NEXT" ]]; then
echo "This script can only be run on the $BRANCH_NEXT branch."
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
exit 1
fi

# Keep track of the current commit sha
LAST_COMMIT_ON_NEXT=$(git rev-parse --short HEAD)
echo "LAST_COMMIT_ON_NEXT: $LAST_COMMIT_ON_NEXT"

# Change the version to "next" before building the docs
echo "export default \"next\";" > ./build/version.mjs

echo ""
echo "Building docs..."
yarn build:docs

# Undo the change to the version, to switch branches
git checkout -- ./build/version.mjs

echo ""
echo "Switching to the $BRANCH_GH_PAGES branch..."
git checkout $BRANCH_GH_PAGES

echo ""
echo "Replacing the existing \`next\` docs with a copy of the new docs..."
rm -rf next && mv docs/ next/

# The built files have links to the `master` branch on GitHub.
# Find and replace those links to point to the next branch. Replace:
# - `/tree/master` with `/tree/$BRANCH_NEXT`
# - `/blob/master` with `/blob/$BRANCH_NEXT`
echo ""
echo "Replacing links to \`master\` with links to \`$BRANCH_NEXT\`..."
BRANCH_NEXT_SLASH_ESCAPED=$(echo "$BRANCH_NEXT" | sed 's/\//\\\//g')
find next/ -type f -exec sed -i -e "s/\/tree\/master/\/tree\/$BRANCH_NEXT_SLASH_ESCAPED/g" {} \;
find next/ -type f -exec sed -i -e "s/\/blob\/master/\/blob\/$BRANCH_NEXT_SLASH_ESCAPED/g" {} \;

# If there are changes in the built docs, commit and push them
if ! git diff --quiet -- next/; then
echo ""
echo "Committing the changes..."
git add next/
git -c user.name="Josephus Paye II" -c user.email="j.paye96@gmail.com" \
commit -m "Add \`next\` docs for commit $LAST_COMMIT_ON_NEXT"

echo ""
echo "Pushing the changes to the $BRANCH_GH_PAGES branch..."
git push origin $BRANCH_GH_PAGES
else
echo ""
echo "No changes to built docs, skipping publish"
exit 0
fi
56 changes: 56 additions & 0 deletions .github/workflows/publish-docs-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish docs for `next` branch

on:
push:
branches: [next]

# Used to ensure only one instance of the workflow is running at a time, cancels existing runs when there's a new one.
# See https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency.
concurrency:
# `github.workflow` is workflow name, `github.ref` is current branch/tag identifier
group: ${{ format('{0}:{1}', github.workflow, github.ref) }}
cancel-in-progress: true

jobs:
check_for_changes:
name: Check for changes
runs-on: ubuntu-22.04
outputs:
has_workflow_changes: ${{ steps.filter.outputs.workflow_changes }}
has_docs_changes: ${{ steps.filter.outputs.docs_changes }}
has_src_changes: ${{ steps.filter.outputs.src_changes }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Check for Changes
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
workflow_changes:
- '.github/workflows/publish-docs-next*'
docs_changes:
- 'docs-src/**'
src_changes:
- 'src/**'

publish_docs:
name: "Build and publish docs to GitHub Pages"
runs-on: "ubuntu-latest"
needs: ["check_for_changes"]
if: |
needs.check_for_changes.outputs.has_workflow_changes == 'true' ||
needs.check_for_changes.outputs.has_docs_changes == 'true' ||
needs.check_for_changes.outputs.has_src_changes == 'true'
steps:
- uses: actions/checkout@v3
with:
ref: next
fetch-depth: 0 # fetch all history so we can switch branches to `gh-pages`
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: bash .github/workflows/publish-docs-next.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ _reminder
Thumbs.db
npm-debug.log
.DS_Store
docs
4 changes: 3 additions & 1 deletion Customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ You can customize the components by overriding Sass variables and importing the
2. If you're using Vite, add the following to `vite.config.js` ([more details here](https://vitejs.dev/config/shared-options.html#css-preprocessoroptions)):

```js
const scssVariablesFile = path.resolve(__dirname, "./src/styles/variables.scss").replace(/\\/g, "/");
const scssVariablesFile = path
.resolve(__dirname, "./src/styles/variables.scss")
.replace(/\\/g, "/");
export default defineConfig({
css: {
preprocessorOptions: {
Expand Down
1 change: 1 addition & 0 deletions build/vite.config.docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import autoprefixer from "autoprefixer";
import options from "./options.mjs";

export default defineConfig({
base: "./", // Use relative paths for assets in built index.html
plugins: [vue()],
server: {
port: 9000,
Expand Down
4 changes: 3 additions & 1 deletion docs-src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export default {
},

versionUrl() {
return `https://github.com/JosephusPaye/Keen-UI/releases/tag/v${this.version}`;
return this.version === "next"
? "https://github.com/JosephusPaye/Keen-UI/tree/next"
: `https://github.com/JosephusPaye/Keen-UI/releases/tag/v${this.version}`;
},
},

Expand Down
17 changes: 14 additions & 3 deletions docs-src/DocsBrand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class="keen-docs-brand__version"
rel="noopener"
target="_blank"
title="View release notes"
:href="versionUrl"
>v{{ version }}</a
:title="displayVersion.title"
:href="displayVersion.url"
>{{ displayVersion.label }}</a
>

<a
Expand Down Expand Up @@ -44,6 +44,16 @@ export default {
versionUrl: String,
repoUrl: String,
},

computed: {
displayVersion() {
return {
url: this.versionUrl,
title: this.version === "next" ? "View `next` branch on Github" : "View release notes",
label: this.version === "next" ? "next" : `v${this.version}`,
};
},
},
};
</script>

Expand All @@ -65,6 +75,7 @@ export default {
font-size: 0.9rem;
opacity: 0.7;
vertical-align: super;
padding-left: 0.4rem;

&:hover,
&:focus {
Expand Down
28 changes: 16 additions & 12 deletions docs-src/DocsSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ import DocsBrand from "./DocsBrand.vue";
import UiIcon from "@/UiIcon.vue";
import UiSelect from "@/UiSelect.vue";

import version from "../build/version.mjs";

const versions = [
{ label: "0.8.x", value: "0.8.9" },
{ label: "1.0.x", value: "1.0.1" },
{ label: "1.1.x", value: "1.1.2" },
{ label: "1.2.x", value: "1.2.1" },
{ label: "1.3.x", value: "1.3.2" },
{ label: "1.4.x", value: "1.4.0" },
{ label: "next", value: "next" },
];

const selectedVersion = versions.find((v) => v.value === version) ?? versions[versions.length - 2];

export default {
components: {
DocsBrand,
Expand All @@ -90,18 +104,8 @@ export default {

data() {
return {
versions: [
{ label: "0.8.x", value: "0.8.9" },
{ label: "1.0.x", value: "1.0.1" },
{ label: "1.1.x", value: "1.1.2" },
{ label: "1.2.x", value: "1.2.1" },
{ label: "1.3.x", value: "1.3.2" },
{ label: "1.4.x", value: "1.4.0" },
],
selectedVersion: {
label: "1.4.x",
value: "1.4.0",
},
versions,
selectedVersion,
menu,
};
},
Expand Down
1 change: 0 additions & 1 deletion docs/docs.bundle.css

This file was deleted.