diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 0000000..4bd9ecb --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,22 @@ +name: 'Install' +description: 'Sets up Node, and installs dependencies' + +runs: + using: 'composite' + steps: + - name: Set up PNPM + uses: pnpm/action-setup@v3 + with: + version: '7' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: Install dependencies + shell: bash + run: | + corepack enable + pnpm install diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 0000000..7efa2d1 --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,18 @@ +name: 'Lint Code' +description: 'Runs Commitlint, ESLint, and Prettier to ensure code quality.' + +runs: + using: 'composite' + steps: + - name: Run Commitlint + shell: bash + run: | + git log -1 --pretty=%B | pnpm exec commitlint + + - name: Run ESLint + shell: bash + run: pnpm eslint . --max-warnings=0 + + - name: Run Prettier + shell: bash + run: pnpm prettier --check . diff --git a/.github/lib/dependencies.workflow.yml b/.github/lib/dependencies.workflow.yml deleted file mode 100644 index 6eda8d3..0000000 --- a/.github/lib/dependencies.workflow.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Dependencies Workflow - -on: - workflow_call: - -jobs: - install-dependencies: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install pnpm - run: npm install -g pnpm - - - name: Install dependencies with pnpm - run: pnpm install diff --git a/.github/lib/linter.workflow.yml b/.github/lib/linter.workflow.yml deleted file mode 100644 index c34a721..0000000 --- a/.github/lib/linter.workflow.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Linter Workflow - -on: - workflow_call: - secrets: - GITHUB_TOKEN: - description: 'GitHub Token with necessary permissions' - required: true - -jobs: - code-quality: - runs-on: ubuntu-latest - - permissions: - pull-requests: write - contents: write - pages: write - id-token: write - - concurrency: - group: 'code-quality-${{ github.ref }}' - cancel-in-progress: false - - steps: - - name: Calls Install Dependencies - uses: ./.github/lib/dependencies.workflow.yml - - - name: Run Commitlint - run: | - git log -1 --pretty=%B | pnpm exec commitlint - - - name: Run ESLint - run: pnpm eslint . --max-warnings=0 - - - name: Run Prettier - run: pnpm prettier --check . diff --git a/.github/lib/release.workflow.yml b/.github/lib/release.workflow.yml deleted file mode 100644 index e71eb4d..0000000 --- a/.github/lib/release.workflow.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: Release Workflow - -on: - workflow_call: - inputs: - release-branch-prefix: - description: 'Prefix for release branches' - required: false - type: string - default: 'release-' - release-label: - description: 'Label to add to the release pull request' - required: false - type: string - default: 'release' - secrets: - GH_TOKEN: - description: 'GitHub Personal Access Token with repo permissions' - required: true - PAT_FORCE_PUSH: - description: 'Personal Access Token with permissions to push to protected branches' - required: true - -permissions: - pull-requests: write - contents: write - pages: write - id-token: write - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Build Assets - run: ${{ inputs.build-command }} - - - name: Run Semantic Release - id: semantic_release - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - run: npx semantic-release - - - name: Create Release Branch - if: success() && steps.semantic_release.outputs.nextRelease - run: | - VERSION=${{ steps.semantic_release.outputs.nextRelease.version }} - git checkout -b ${{ inputs.release-branch-prefix }}${VERSION} - - - name: Push Release Branch - if: success() && steps.semantic_release.outputs.nextRelease - env: - PAT: ${{ secrets.PAT_FORCE_PUSH }} - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git remote set-url origin https://x-access-token:${PAT}@github.com/${{ github.repository }}.git - git push origin ${{ inputs.release-branch-prefix }}${VERSION} --force - - - name: Extract Version from package.json - id: extract_version - run: | - VERSION=$(jq -r .version package.json) - echo "version=$VERSION" >> $GITHUB_OUTPUT - - - name: Extract Changelog - id: changelog - run: | - CHANGELOG=$(awk '/^## \[/ {print; exit}' CHANGELOG.md) - echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT - - - name: Create Pull Request to Main - if: success() && steps.semantic_release.outputs.nextRelease - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - title: 'chore/release: ${{ steps.extract_version.outputs.version }}' - body: | - This is an automated pull request for release version `${{ steps.extract_version.outputs.version }}`. - - **Changelog:** - ``` - ${{ steps.changelog.outputs.changelog }} - ``` - head: ${{ inputs.release-branch-prefix }}${{ steps.extract_version.outputs.version }} - base: main - commit-message: 'chore/release: ${{ steps.extract_version.outputs.version }} [skip ci]' - labels: ${{ inputs.release-label }} diff --git a/.github/workflows/ci.documentation.yml b/.github/workflows/ci.documentation.yml index 99d150a..f4761f1 100644 --- a/.github/workflows/ci.documentation.yml +++ b/.github/workflows/ci.documentation.yml @@ -27,6 +27,12 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} # Ensure access to private repo fetch-depth: 0 + - name: Install Dependencies + uses: ./lib/actions/install-dependencies + + - name: Run Lint Checks + uses: ./.github/actions/lint + - name: Build docs using Writerside Docker builder uses: JetBrains/writerside-github-action@v4 with: diff --git a/.github/workflows/ci.lint.yml b/.github/workflows/ci.lint.yml index 2bf802a..0ca0a1c 100644 --- a/.github/workflows/ci.lint.yml +++ b/.github/workflows/ci.lint.yml @@ -7,7 +7,7 @@ permissions: id-token: write concurrency: - group: 'pages' + group: 'code-quality-${{ github.ref }}' cancel-in-progress: false on: @@ -21,15 +21,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 - name: Install Dependencies - uses: ./.github/lib/dependencies.workflow.yml - - - name: Code Quality - uses: ./.github/lib/linter.workflow.yml - + uses: ./.github/actions/install + - name: Run Lint Checks + uses: ./.github/actions/lint diff --git a/.github/workflows/ci.release.yml b/.github/workflows/ci.release.yml index 4e09ecf..675c4fd 100644 --- a/.github/workflows/ci.release.yml +++ b/.github/workflows/ci.release.yml @@ -1,4 +1,10 @@ -name: Call Release Workflow +name: Release Workflow + +permissions: + pull-requests: write + contents: write + pages: write + id-token: write on: push: @@ -10,19 +16,68 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} # Ensure access to private repo fetch-depth: 0 - name: Install Dependencies - uses: ./.github/lib/dependencies.workflow.yml + uses: ./lib/actions/install-dependencies - - name: Release - uses: ./.github/lib/release.workflow.yml - with: - release-branch-prefix: 'release-' - release-label: 'release' + - name: Run Lint Checks + uses: ./.github/actions/lint + + - name: Build Assets + run: ${{ inputs.build-command }} + + - name: Run Semantic Release + id: semantic_release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + run: npx semantic-release + + - name: Create Release Branch + if: success() && steps.semantic_release.outputs.nextRelease + run: | + VERSION=${{ steps.semantic_release.outputs.nextRelease.version }} + git checkout -b ${{ inputs.release-branch-prefix }}${VERSION} + + - name: Push Release Branch + if: success() && steps.semantic_release.outputs.nextRelease env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PAT_FORCE_PUSH: ${{ secrets.GH_TOKEN }} + PAT: ${{ secrets.PAT_FORCE_PUSH }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git remote set-url origin https://x-access-token:${PAT}@github.com/${{ github.repository }}.git + git push origin ${{ inputs.release-branch-prefix }}${VERSION} --force + + - name: Extract Version from package.json + id: extract_version + run: | + VERSION=$(jq -r .version package.json) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Extract Changelog + id: changelog + run: | + CHANGELOG=$(awk '/^## \[/ {print; exit}' CHANGELOG.md) + echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT + + - name: Create Pull Request to Main + if: success() && steps.semantic_release.outputs.nextRelease + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: 'chore/release: ${{ steps.extract_version.outputs.version }}' + body: | + This is an automated pull request for release version `${{ steps.extract_version.outputs.version }}`. + + **Changelog:** + ``` + ${{ steps.changelog.outputs.changelog }} + ``` + head: ${{ inputs.release-branch-prefix }}${{ steps.extract_version.outputs.version }} + base: main + commit-message: 'chore/release: ${{ steps.extract_version.outputs.version }} [skip ci]' + labels: ${{ inputs.release-label }}