Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4abab37
chore(CRC-184): Migrate to docker action
javierbrea Mar 14, 2025
db7a4cd
chore(CRC-184): Ignore dist folder
javierbrea Mar 14, 2025
9b03f8a
chore(CRC-184): Change workflows
javierbrea Mar 14, 2025
0775a2b
test(CRC-184): Fix unit tests
javierbrea Mar 14, 2025
d00b430
chore(CRC-184): Bundle dependencies due to private package
javierbrea Mar 14, 2025
39a4a6d
chore(CRC-184): Move private dependency to optional
javierbrea Mar 14, 2025
cb035e1
chore(CRC-184): Do not build package. Use bundled dist
javierbrea Mar 14, 2025
87271e5
test(CRC-184): Add mermaid diagram to test
javierbrea Mar 14, 2025
19ad5a1
test(CRC-184): Install chromium and pupetter dependencies
javierbrea Mar 14, 2025
a95f34e
test(CRC-184): Install chromium and pupetter dependencies
javierbrea Mar 14, 2025
cc32322
test(CRC-184): Install chromium and pupetter dependencies
javierbrea Mar 14, 2025
f594896
test(CRC-184): Install chromium and pupetter dependencies
javierbrea Mar 14, 2025
42c997e
test(CRC-184): Do not install
javierbrea Mar 14, 2025
4120e7f
test(CRC-184): Do not install
javierbrea Mar 14, 2025
ec228a3
chore: Set log level to debug
javierbrea Mar 14, 2025
33a84cc
docs: Fix contributing
javierbrea Mar 14, 2025
7c0ea24
chore(CRC-184): Try to make mermad-cli work in Docker
javierbrea Mar 14, 2025
d26c406
chore: Change Docker config
javierbrea Mar 17, 2025
4707967
feat: Install mermaid fonts
javierbrea Mar 17, 2025
5454abb
chore: Fix bundled code programattically
javierbrea Mar 17, 2025
53434c7
chore: Disable cspell
javierbrea Mar 17, 2025
00be6ce
chore: Remove file
javierbrea Mar 17, 2025
6ddc616
feat: Add Mermaid diagrams example to use it in E2E tests
javierbrea Mar 17, 2025
ca98fe7
chore: Fix lint
javierbrea Mar 17, 2025
621e196
chore: Add preprocessor to test how to use external modules
javierbrea Mar 17, 2025
6e214a3
chore: Change file to cjs
javierbrea Mar 17, 2025
59a37d7
chore: Try using ejs from cdn
javierbrea Mar 17, 2025
ac27729
chore: Try using ejs from cdn
javierbrea Mar 17, 2025
0d4c29a
chore: Require ejs in function
javierbrea Mar 17, 2025
ccefb46
chore: Require ejs in function
javierbrea Mar 17, 2025
12e9729
chore: Remove config test
javierbrea Mar 17, 2025
98ddbe7
feat(CRC-184): Add notice message
javierbrea Mar 17, 2025
3e49f4b
chore: Add link to notice
javierbrea Mar 17, 2025
eb357f7
chore: Fix url
javierbrea Mar 17, 2025
c4ba98d
chore: Fix link
javierbrea Mar 17, 2025
fec813e
chore: Install before copying
javierbrea Mar 17, 2025
2b4aecc
chore(release): Upgrade version
javierbrea Mar 17, 2025
a413c62
chore: Do not run E2E tests in branch
javierbrea Mar 17, 2025
e5ebba5
chore: Do not build branch
javierbrea Mar 17, 2025
9bc016e
chore: Remove url
javierbrea Mar 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!package.json
!pnpm-lock.yaml
!bin/
!dist/
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
# may be useful to set it to `true`.
ACTIONS_STEP_DEBUG=true

# E2E tests

CONFLUENCE_URL=foo-confluence.atlassian.net
CONFLUENCE_PAT=foo-access-token
CONFLUENCE_README_PAGE_ID=foo-readme-page-id
CONFLUENCE_CHANGELOG_PAGE_ID=foo-changelog-page-id

# GitHub Actions inputs should follow `INPUT_<name>` format (case-sensitive).
# Hyphens should not be converted to underscores!
INPUT_DOCS-DIR="./docs"
Expand Down
50 changes: 22 additions & 28 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,48 @@ Thank you for being part of the Telefónica Innovación Digital Open Source Comm
1. :hammer_and_wrench: Install the dependencies

```bash
npm install
pnpm install
```

1. :building_construction: Package the TypeScript for distribution
2. :white_check_mark: Run the unit tests

```bash
npm run package
```

1. :white_check_mark: Run the unit tests

```bash
$ npm run test:unit
$ pnpm test:unit

PASS test/unit/specs/main.spec.ts
PASS test/unit/specs/index.spec.ts
...

## Test the action locally

The [`@github/local-action`](https://github.com/github/local-action) utility
can be used to test your action locally. It is a simple command-line tool
that "stubs" (or simulates) the GitHub Actions Toolkit. This way, you can run
your TypeScript action locally without having to commit and push your changes
to a repository.
The action is a Docker container that runs a Node.js script. To test the action locally, you can run the Docker compose file in the root of the repository. This will build the Docker image and run the action in a container.

The `local-action` utility can be run in the following ways:
```bash
$ docker compose build
$ docker compose run action
```

- Visual Studio Code Debugger
> [!CAUTION]
> The Docker image won't work in some systems due to the usage of Chromium, as in MacOS with M1 processors. In this case, you can [run the Node.js code instead](#test-the-nodejs-code-locally).

Make sure to review and, if needed, update
[`.vscode/launch.json`](./.vscode/launch.json)
You can provide a `.env` file to set environment variables used by the GitHub Actions Toolkit. For more information, see the example file, [`.env.example`](./.env.example), and the
[GitHub Actions Documentation](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).

- Terminal/Command Prompt
> [!IMPORTANT]
> The root workspace directory is mounted as a volume in the container in the `/github/workspace` folder. You can set another workspace subdirectory for testing the synchronization locally by setting the `INPUT_CWD` environment variable to the desired directory (e.g. `INPUT_CWD=test-action`).

```bash
# npx local action <action-yaml-path> <entrypoint> <dotenv-file>
npx local-action . src/main.ts .env
```
### Test the Node.js code locally

You can provide a `.env` file to the `local-action` CLI to set environment
variables used by the GitHub Actions Toolkit. For more information, see the example
file, [`.env.example`](./.env.example), and the
[GitHub Actions Documentation](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).
Apart from running the unit tests, you can also run the Node.js code locally by following these steps:

* Modify the `src/action/main.ts` file to change the `BASE_CWD` variable from `/github/workspace` to the desired directory (e.g. `test-action`).
* Build the action code using the `pnpm build` command.
* Add your markdown file and configuration files to the desired directory (e.g. `test-action/markdown-confluence-sync.config.js` and `test-action/docs/foo.md`).
* Run the action code using `node bin/markdown-confluence-sync-action.js`.

## E2E tests

This project includes end-to-end tests, consisting in a workflow that uses the action to sync the documentation of the project itself to a Confluence page, and then checks if the page was updated correctly.
This project includes end-to-end tests, consisting in a workflow that uses the action to sync the documentation of the project itself to a Confluence page, and then checks if the page was updated correctly. Once the documentation has been synced, you can run tests using the following command:

```bash
npm run test:e2e
Expand Down
12 changes: 6 additions & 6 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ inputs:
runs:
using: composite
steps:
- name: Setup Node.js
id: setup-node
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm
cache: pnpm
- uses: DamianReeves/[email protected]
with:
path: .npmrc
contents: |
@tid-xcut:registry=https://nexus.tid.es/repository/npm-xcut-components/
//nexus.tid.es/repository/npm-xcut-components/:_auth=${{ inputs.npm-token }}
write-mode: append
- name: Install Dependencies
- name: Install Node.js dependencies
shell: bash
id: npm-ci
run: npm ci
run: pnpm install
30 changes: 15 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,25 @@ jobs:
with:
npm-token: ${{ secrets.NPM_TOKEN_XCUT }}

- name: Build
id: build
run: pnpm build

- name: Lint
id: npm-lint
run: npm run lint
run: pnpm lint

- name: Check spelling
id: npm-check-spelling
run: npm run cspell
run: pnpm cspell

- name: Check TypeScript types
id: npm-check-types
run: npm run check:types
run: pnpm check:types

- name: Test unit
id: npm-test
run: npm run test:unit

- name: Upload coverage
id: upload-coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/

- name: Build dist/ Directory
id: build
run: npm run package
run: pnpm test:unit

# This will fail the workflow if the `dist/` directory is different than
# expected.
Expand All @@ -80,3 +73,10 @@ jobs:
with:
name: dist
path: dist/

- name: Upload coverage
id: upload-coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
2 changes: 2 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
with:
mode: id
docs-dir: '.'
confluence-notice-message: 'This page is automatically generated from content in the <a href="https://github.com/Telefonica/markdown-confluence-sync-action" target="_blank">markdown-confluence-sync-action repository</a> Changes made manually will be lost, you should edit this page in Github instead.'
files-pattern: '*.md'
files-metadata: |
[
Expand All @@ -45,6 +46,7 @@ jobs:
confluence-url: ${{ vars.CONFLUENCE_URL }}
confluence-space-key: ${{ vars.CONFLUENCE_SPACE_KEY }}
confluence-personal-access-token: ${{ secrets.CONFLUENCE_PAT }}
log-level: debug

test-e2e:
environment: production
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
node_modules
.npmrc

# Test action locally
test-action

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Deprecated
#### Removed

## [2.0.0] - 2025-03-18

### Changed

* feat(BREAKING CHANGE): Throw an error in case the `cwd` input is absolute, because the action only has access to the repository files
* chore: Use Docker action instead of Node.js action in order to install Chromium and Puppeteer
* chore: Use Pnpm instead of NPM
* chore: Move `dependencies` to `devDependencies`, because in runtime the action uses only the bundled code, and it installs the mermaid dependencies by itself in the Docker image. This is because the `@tid-xcut` libraries are in a private repository, and the action cannot install them in the Docker image. Some fixes are applied to the bundled code to make it work in the Docker image.

### Fixed

* fix: Generate mermaid diagrams in the Confluence page

### Added

* docs: Add automation notice to Confluence pages containing the action docs
* test: Add mermaid diagram to readme.md file, and test that it has been synced to Confluence in E2E tests


## [1.2.0] - 2025-03-13

### Changed
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM --platform=linux/amd64 node:22
RUN corepack enable && corepack prepare [email protected] --activate

# We don't need the standalone Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"

# cspell: disable
# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer, and the fonts needed for Mermaid
RUN apt-get update && apt-get install curl gnupg -y \
&& curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install google-chrome-stable -y --no-install-recommends \
&& apt-get install chromium -y \
&& apt-get install -y \
fonts-noto-cjk fonts-noto-color-emoji \
fonts-terminus fonts-dejavu fonts-freefont-ttf \
fonts-font-awesome fonts-inconsolata \
fonts-linuxlibertine \
&& fc-cache -f \
&& rm -rf /var/lib/apt/lists/*

# NOTE: We need to install Mermaid globally, as we are not installing the package.json dependencies due to private packages
RUN npm i -g [email protected] @mermaid-js/[email protected]

WORKDIR /usr/src/app

COPY . .

ENTRYPOINT [ "node", "/usr/src/app/bin/markdown-confluence-sync-action.js"]
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This action syncs markdown files to Confluence using the [Markdown Confluence Sy
- [Tree operation mode](#tree-operation-mode)
- [Flat operation mode](#flat-operation-mode)
- [Id operation mode](#id-operation-mode)
- [Mermaid diagrams](#mermaid-diagrams)
- [Configuration](#configuration)
- [Inputs](#inputs)
- [Configuration file](#configuration-file)
Expand All @@ -21,7 +22,7 @@ This action syncs markdown files to Confluence using the [Markdown Confluence Sy

* It creates/updates/deletes [Confluence](https://www.atlassian.com/es/software/confluence) pages based on markdown files in a directory.
* Upload images to Confluence and update links in markdown files
* Supports Mermaid diagrams
* Supports [Mermaid diagrams](#mermaid-diagrams)
* Per-page configuration using [frontmatter metadata](https://jekyllrb.com/docs/front-matter/)
* Works great with [Docusaurus](https://docusaurus.io/)
* Three modes of operation:
Expand Down Expand Up @@ -62,7 +63,7 @@ docs/

```yaml
- name: Sync markdown files to Confluence
uses: Telefonica/markdown-confluence-sync-action@v1
uses: Telefonica/markdown-confluence-sync-action@v2
with:
mode: tree
docs-dir: './docs'
Expand All @@ -88,7 +89,7 @@ For example:

```yaml
- name: Sync markdown files to Confluence
uses: Telefonica/markdown-confluence-sync-action@v1
uses: Telefonica/markdown-confluence-sync-action@v2
with:
mode: id
docs-dir: '.'
Expand Down Expand Up @@ -131,7 +132,7 @@ confluence_page_id: 123456789

```yaml
- name: Sync markdown files to Confluence
uses: Telefonica/markdown-confluence-sync-action@v1
uses: Telefonica/markdown-confluence-sync-action@v2
with:
mode: flat
docs-dir: './docs'
Expand All @@ -141,6 +142,23 @@ confluence_page_id: 123456789
confluence-personal-access-token: ${{ secrets.CONFLUENCE_PAT }}
```

### Mermaid diagrams

Mermaid diagrams are supported in the markdown files. The action will render the diagrams as images and upload them to Confluence.

```markdown
```mermaid
graph TD;
A-->B;
A-->C;
```

```mermaid
graph TD;
A-->B;
A-->C;
```

## Configuration

The action accepts a configuration file in the root of the repository, and it can be also configured using Github action inputs or even environment variables.
Expand Down Expand Up @@ -169,7 +187,7 @@ The action accepts a configuration file in the root of the repository, and it ca
| `confluence-notice-template` | Template string to use for the notice message | No | |
| `confluence-dry-run` | Dry run mode: Do not update Confluence pages. Only log pages to sync | No | `false `|
| `log-level` | Log level: `silent`, `silly`, `debug`, `verbose`, `info`, `warn`, `error` | No | `info` |
| `cwd` | Current working directory. Path from where resolve `docs-dir`, `files-pattern`, and search for the configuration file | No | `.` |
| `cwd` | Current working directory. Path from where resolve `docs-dir`, `files-pattern`, and search for the configuration file. It must be relative to the repository folder | No | `.` |

> [!NOTE]
> Some markdown-confluence-sync options are not available as inputs in the action, as `preprocessor`. If you need to use them, you can set them in the [configuration file](#configuration-file) or using [environment variables](#environment-variables). Refer to the [Markdown Confluence Sync library docs](https://github.com/Telefonica/cross-confluence-tools/tree/main/components/markdown-confluence-sync#configuration-file) for further info about all available options.
Expand Down
5 changes: 2 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ inputs:
cwd:
description: 'Current working directory. Path from where the library resolve docsDir, filesPattern, and searches for configuration files'
type: string

runs:
using: node20
main: dist/index.js
using: docker
image: Dockerfile
7 changes: 7 additions & 0 deletions bin/markdown-confluence-sync-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

// SPDX-FileCopyrightText: 2025 Telefónica Innovación Digital
// SPDX-License-Identifier: Apache-2.0

import { run } from "../dist/index.js";
run();
Loading