From 74d32971a7f30d89345ce6f93c123388306cb8d8 Mon Sep 17 00:00:00 2001 From: Mathieu Ancelin Date: Tue, 19 Dec 2023 14:01:51 +0100 Subject: [PATCH] change version in publish --- .github/workflows/publish_documentation.yaml | 13 +++--- .../change-doc-version-github-action.js | 41 +++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 scripts/release/change-doc-version-github-action.js diff --git a/.github/workflows/publish_documentation.yaml b/.github/workflows/publish_documentation.yaml index 59452d634..eff75237e 100644 --- a/.github/workflows/publish_documentation.yaml +++ b/.github/workflows/publish_documentation.yaml @@ -3,8 +3,10 @@ name: publish-otoroshi-documentation on: workflow_dispatch: inputs: - version: - description: "Current version" + version_from: + description: "Current version (ie. 16.12.0-dev)" + version_to: + description: "Published version (ie. 16.11.2)" jobs: release-otoroshi: @@ -32,11 +34,12 @@ jobs: id: run-doc-process env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION_FROM: ${{ inputs.version_from }} + VERSION_TO: ${{ inputs.version_to }} DISPLAY: :1 run: | - LOC=$(pwd) - # TODO: change version in files - # TODO: node ./scripts/release/change-doc-version-github-action.js + export WHERE=$(pwd) + node ./scripts/release/change-doc-version-github-action.js sh ./scripts/doc.sh all # TODO: git commit -am 'publish documentation' # TODO: git push origin master diff --git a/scripts/release/change-doc-version-github-action.js b/scripts/release/change-doc-version-github-action.js new file mode 100644 index 000000000..3d7160e50 --- /dev/null +++ b/scripts/release/change-doc-version-github-action.js @@ -0,0 +1,41 @@ +const path = require('path'); +const fs = require('fs'); + +const files = [ + { file: './kubernetes/kustomize/overlays/cluster/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { file: './kubernetes/kustomize/overlays/cluster-baremetal/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { file: './kubernetes/kustomize/overlays/cluster-baremetal-daemonset/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { file: './kubernetes/kustomize/overlays/simple/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { file: './kubernetes/kustomize/overlays/simple-baremetal/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { file: './kubernetes/kustomize/overlays/simple-baremetal-daemonset/deployment.yaml', replace: (from, to, source) => source.replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) }, + { + file: './manual/src/main/paradox/deploy/kubernetes.md', + replace: (from, to, source) => source.replace(`?ref=v${from}`, `?ref=v${to}`).replace(`maif/otoroshi:${from}`, `maif/otoroshi:${to}`) + }, + { file: './manual/src/main/paradox/code/openapi.json' }, + { file: './manual/src/main/paradox/getting-started.md' }, + { file: './manual/src/main/paradox/how-to-s/import-export-otoroshi-datastore.md' }, + { file: './manual/src/main/paradox/how-to-s/setup-otoroshi-cluster.md' }, + { file: './manual/src/main/paradox/includes/fetch-and-start.md' }, + { file: './manual/src/main/paradox/includes/initialize.md' }, + { file: './manual/src/main/paradox/index.md' }, + { file: './manual/src/main/paradox/install/get-otoroshi.md' }, + { file: './manual/src/main/paradox/topics/expression-language.md' }, + { file: './manual/src/main/paradox/snippets/build.gradle' }, + { file: './manual/src/main/paradox/snippets/build.sbt' }, + { file: './manual/src/main/paradox/snippets/fetch.sh' }, +]; + +function changeVersion(where, from, to, exclude = []) { + console.log(`Changing version from '${from}' to '${to}'`) + files.filter(f => !(exclude.indexOf(f.file) > -1)).map(file => { + const filePath = path.resolve(where, file.file); + const content = fs.readFileSync(filePath, 'utf8'); + console.log('Changing version in', filePath); + const replace = file.replace || ((f, t, s) => s.replace(new RegExp(f.replace(new RegExp('\\.', 'g'), '\\.'), 'g'), t)); + const newContent = replace(from, to, content); + fs.writeFileSync(filePath, newContent); + }); +} + +changeVersion(process.env.WHERE, process.env.VERSION_FROM, process.env.VERSION_TO)