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

Fix local development and preview #133

Merged
merged 12 commits into from
Jul 10, 2023
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
14 changes: 6 additions & 8 deletions antora-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This file is changed during the build process, so if you want to save your changes
# You'd need to commit them before running the `npm run build` script, or
# just comment the `postbuild` script that restores this file
#
site:
title: Decidim Docs
url: https://docs.decidim.org
Expand All @@ -6,17 +10,11 @@ content:
sources:
- url: https://github.com/decidim/documentation
start_path: docs/en
branches:
- release/0.27-stable
- release/0.26-stable
- develop
branches: [release/0.27-stable, release/0.26-stable, develop]
edit_url: "https://github.com/decidim/documentation/edit/{refname}/{path}"
- url: https://github.com/decidim/decidim
start_path: docs
branches:
- release/0.27-stable
- release/0.26-stable
- develop
branches: [release/0.27-stable, release/0.26-stable, develop]
- url: https://github.com/decidim/decidim-bulletin-board
start_path: docs
branches: develop
Expand Down
73 changes: 67 additions & 6 deletions bin/playbook-changer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
#!/bin/env node
// Antora playbook changer script for Decidim documentation
//
// Changes the playbook accordingly to its environment
//

const fs = require('fs')

const scriptName = process.argv[1];
const environment = process.argv[2];
const antoraPlaybook = "antora-playbook.yml";

let headRef;
let baseRef;
let url;

console.log(process.env);

// Infers base branch reference according to the head reference
//
// If the head reference starts with the version number (i.e. "v0.26/fix/preview"), returns the base branch reference (i.e. "release/0.26-stable")
// If not, then returns "develop"
//
// @param {string} headRef - The head reference. Examples: "v0.26/fix/preview" or "fix/preview"
// @returns {string} The base reference. Examples "release/0.26-stable" or "develop"
function baseFromHead(headRef) {
let baseRef;

if (headRef.startsWith("v0.")) {
const version = headRef.split("/")[0].replace("v");
baseRef = `release/${version}-stable`;
} else {
baseRef = "develop";
};

function helpMessage () {
console.log(`${scriptName} - Antora playbook changer script for Decidim documentation
return baseRef;
}

Changes the playbook accordingly to its environment`);
console.log(process.env);
if (process.env.CONTEXT === "deploy-preview" || process.env.RUNNER_ENVIRONMENT == "github-hosted") {
// We're in CI and we need to adapt the head of the playbook
headRef = process.env.HEAD || process.env.GITHUB_HEAD_REF;
if (process.env.GITHUB_BASE_REF != undefined) {
baseRef = process.env.GITHUB_BASE_REF
} else {
baseRef = baseFromHead(headRef);
}
} else if (process.env.CI === "true") {
// We're in production so we don't need to change anything
return;
} else {
// We're in development and we need to adapt the head and also the URL
headRef = "HEAD";
baseRef = "develop";
url = ".";
}

helpMessage();
fs.readFile(antoraPlaybook, "utf8", function (err,data) {
if (err) {
return console.err(err);
}

let result = data.replace(baseRef, headRef);
if (url != undefined) {
result = result.replace("https://github.com/decidim/documentation", url);
}

console.log(result);

fs.writeFile(antoraPlaybook, result, "utf8", function (err) {
if (err) {
return console.err(err);
}
});
});

2 changes: 1 addition & 1 deletion docs/en/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
*** xref:develop:open-data.adoc[Open Data]
*** xref:develop:permissions.adoc[Permissions]
*** xref:develop:profiling.adoc[Profiling]
*** xref:develop:releases.adoc[Releases]
*** xref:develop:maintainers/releases.adoc[Releases]
*** xref:develop:reminders.adoc[Reminders]
*** xref:develop:templates.adoc[Templates]
*** xref:develop:testing.adoc[Testing]
Expand Down
5 changes: 5 additions & 0 deletions docs/en/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Decidim is a framework that allows anybody to create and configure a website pla

You’ve found the documentation for Decidim. Learn about the project at https://decidim.org[decidim.org].

[NOTE]
====
This is the documentation for the `develop` branch. You can see this same documentation site for other versions: xref:v0.26@ROOT:index.adoc[v0.26] and xref:v0.27@ROOT:index.adoc[v0.27]
====

// * Read the xref:ROOT:getting-started.adoc[Getting Started guide]

The documentation covers xref:install:index.adoc[installing], xref:configure:index.adoc[configuring], and xref:admin:index.adoc[running] your own Decidim site.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"prebuild": "./bin/playbook-changer.js",
"build": "antora antora-playbook.yml $@",
"postbuild": "git restore antora-playbook.yml",
"test": "./bin/test"
},
"devDependencies": {
Expand Down