Skip to content

Commit

Permalink
feat(docs): adds shareable Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
csantiago132 committed Sep 30, 2024
1 parent ca220bc commit 6b6b4c1
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 30 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/_base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Setup Workflow

on:
workflow_call:
inputs:
node_version:
type: string
required: true

jobs:
setup:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Cache pnpm store
uses: actions/cache@v3
with:
path: ~/.pnpm-store # Path to pnpm store
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} # Cache key based on OS and lockfile hash
restore-keys: |
${{ runner.os }}-pnpm-
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version}}

- name: Install dependencies
run: pnpm install
17 changes: 17 additions & 0 deletions .github/workflows/commitlint_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Commitlint Check

on:
workflow_call:
inputs:
edit:
type: string
required: true
default: '.git/COMMIT_EDITMSG'

jobs:
commitlint:
runs-on: ubuntu-latest

steps:
- name: Run Commitlint
run: pnpm exec commitlint --edit ${{ inputs.edit }}
21 changes: 21 additions & 0 deletions .github/workflows/eslint_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ESLint Check

on:
workflow_call:
inputs:
maxWarnings:
type: string
required: false
default: '0'

jobs:
eslint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
if: ${{ inputs.skip_checkout == false }}
uses: actions/checkout@v3

- name: Run ESLint
run: pnpm exec eslint --max-warnings=${{ inputs.maxWarnings }} .
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
name: Build, Test, and Deploy Documentation

on:
push:
branches: ['main']
workflow_dispatch:
workflow_call:
inputs:
skip_checkout:
type: boolean
default: false
github_token:
type: string
required: true
writerside_instance:
type: string
required: true
default: 'Writerside/dcs'
artifact_name:
type: string
required: true
default: 'webHelpDCS2-all.zip'
docker_version:
type: string
required: true
default: '242.21870'

permissions:
contents: read
Expand All @@ -14,45 +31,30 @@ concurrency:
group: 'pages'
cancel-in-progress: false

env:
INSTANCE: 'Writerside/dcs'
ARTIFACT: 'webHelpDCS2-all.zip'
DOCKER_VERSION: '242.21870'

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Build documentation using Writerside Docker builder
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: List files after build
run: ls -R
instance: ${{ inputs.writerside_instance }}
artifact: ${{ inputs.artifact_name }}
docker-version: ${{ inputs.docker_version }}

- name: Save Writerside artifact with build results
uses: actions/upload-artifact@v4
with:
name: docs
path: |
artifacts/${{ env.ARTIFACT }} # Artifact saved inside artifacts folder
artifacts/report.json # Optional: any reports generated
artifacts/${{ inputs.artifact_name }}
artifacts/report.json
retention-days: 7

- name: Unzip and list Writerside artifact
- name: Unzip Writerside artifact
run: |
unzip -O UTF-8 -qq artifacts/${{ env.ARTIFACT }} -d dir # Unzip from artifacts folder
ls -R dir # List contents of unzipped directory
unzip -O UTF-8 -qq artifacts/${{ inputs.artifact_name }} -d dir
- name: Configure GitHub Pages
uses: actions/configure-pages@v4
Expand All @@ -67,9 +69,9 @@ jobs:
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ inputs.github_token }}

- name: Test documentation using Writerside Checker
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.INSTANCE }}
instance: ${{ inputs.writerside_instance }}
46 changes: 46 additions & 0 deletions .github/workflows/index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI/CD Workflow

on:
pull_request:
push:
branches:
- main

jobs:
setup:
uses: ./_base.yml@v1
with:
node_version: '18'

commitlint:
needs: setup
uses: ./commitlint.yml@v1
with:
edit: '.git/COMMIT_EDITMSG'

eslint:
needs: setup
uses: ./eslint-check.yml@v1
with:
maxWarnings: '0'

prettier:
needs: setup
uses: ./prettier-check.yml@v1

generate-writerside-docs:
needs: setup
if: github.ref == 'refs/heads/main'
uses: ./generate_writerside_docs.yml@v1
with:
npm_token: ${{ secrets.NPM_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}

semantic-release:
needs: setup
if: github.ref == 'refs/heads/main'
uses: ./semantic-release.yml@v1
with:
node_version: '18'
npm_token: ${{ secrets.NPM_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish to NPM

on:
workflow_call:
inputs:
npm_token:
type: string
required: true
npm_access:
type: string
default: 'public'
required: false

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
run: npm publish --access ${{ inputs.npm_access }}
16 changes: 16 additions & 0 deletions .github/workflows/prettier_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Prettier Check

on:
workflow_call:
inputs:
skip_checkout:
type: boolean
default: false

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Run Prettier Check
run: pnpm prettier --check .
22 changes: 22 additions & 0 deletions .github/workflows/semantic_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Semantic Release

on:
workflow_call:
inputs:
npm_token:
type: string
required: true
github_token:
type: string
required: true

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Run Semantic Release
env:
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
GITHUB_TOKEN: ${{ inputs.github_token }}
run: npx semantic-release
Empty file added CHANGELOG.md
Empty file.
1 change: 1 addition & 0 deletions Writerside/dcs.tree
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

<toc-element topic="starter-topic.md"/>
<toc-element topic="How-to-build-test-deploy-Writerside-documentation.md"/>
<toc-element topic="How-to-Set-Up-and-Use-Reusable-GitHub-Actions-Across-Repositories.md"/>
</instance-profile>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# How to Set Up and Use Reusable GitHub Actions Across Repositories

A How-to article is an action-oriented type of document. It explains how to perform a specific task
or solve a problem, and usually contains a sequence of steps. Start with a short introductory
paragraph that explains what users will accomplish by following this procedure, what they need to
perform it for, or define the target audience of the doc.

> **Note**
> This guide assumes that you have installed `@kurocado-studio/style-guide` as a dev. dependency
>
> {style="note"}
## Before you start

It is good practice to list the prerequisites that are required or recommended.

Make sure that:

- First prerequisite
- Second prerequisite

## How to perform a task

Some introductory information.

1. Step with a code block

```bash
run this --that
```

2. Step with a [link](https://www.jetbrains.com)

3. Step with a list.
- List item
- List item
- List item
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
},
"license": "MPL-2.0",
"exports": {
"./gh-actions/gh-docs-actions": "./.github/workflows/deploy_docs.yml",
"./gh-actions/base": "./.github/workflows/_base.yml",
"./gh-actions/commitlint": "./.github/workflows/commitlint.yml",
"./gh-actions/deploy_writerside_docs": "./.github/workflows/deploy_writerside_docs.yml",
"./gh-actions/eslint_check": "./.github/workflows/eslint_check.yml",
"./gh-actions/npm_publish": "./.github/workflows/npm_publish.yml",
"./gh-actions/prettier_check": "./.github/workflows/prettier_check.yml",
"./commitlint": "./src/commitlint/index.js",
"./semantic-release": "./src/semantic-release/index.js",
"./eslint/base": "./src/eslint/eslint.base.js",
Expand Down
6 changes: 4 additions & 2 deletions src/semantic-release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ module.exports = {
[
'@semantic-release/git',
{
// eslint-disable-next-line no-template-curly-in-string -- required by `semantic-release`.
message: 'release: ${nextRelease.version}',
assets: ['package.json', 'CHANGELOG.md'],
message:
// eslint-disable-next-line no-template-curly-in-string -- required by `semantic-release`.
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
},
],
],
Expand Down

0 comments on commit 6b6b4c1

Please sign in to comment.