Skip to content

Commit

Permalink
feat(ci): adds github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
csantiago132 committed Oct 3, 2024
1 parent 9b2e8d8 commit eaf4db1
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 143 deletions.
25 changes: 25 additions & 0 deletions .github/lib/dependencies.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
36 changes: 36 additions & 0 deletions .github/lib/linter.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 .
87 changes: 87 additions & 0 deletions .github/lib/release.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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 }}
File renamed without changes.
35 changes: 35 additions & 0 deletions .github/workflows/ci.lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code Quality

permissions:
pull-requests: write
contents: write
pages: write
id-token: write

concurrency:
group: 'pages'
cancel-in-progress: false

on:
pull_request:
push:
branches:
- main

jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
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


28 changes: 28 additions & 0 deletions .github/workflows/ci.release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Call Release Workflow

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Install Dependencies
uses: ./.github/lib/dependencies.workflow.yml

- name: Release
uses: ./.github/lib/release.workflow.yml
with:
release-branch-prefix: 'release-'
release-label: 'release'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAT_FORCE_PUSH: ${{ secrets.GH_TOKEN }}
54 changes: 0 additions & 54 deletions .github/workflows/ci.yml

This file was deleted.

4 changes: 3 additions & 1 deletion Writerside/dcs.tree
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
start-page="starter-topic.md">

<toc-element topic="starter-topic.md"/>
<toc-element topic="How-to-build-test-deploy-Writerside-documentation.md"/>
<toc-element topic="Workflows.md">
<toc-element topic="How-to-build-test-deploy-Writerside-documentation.md"/>
</toc-element>
<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
Expand Up @@ -2,7 +2,7 @@ Here's the revised guide with the updated assumption:

---

# How to Build, Test & Deploy Writerside Documentation
# Release Workflow

In this guide, you will learn how to set up a **reusable GitHub Actions workflow** to build, test,
and deploy Writerside documentation to GitHub Pages. The reusable workflow will be installed
Expand Down
68 changes: 68 additions & 0 deletions Writerside/topics/Workflows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Automated Release Workflow with `semantic-release`

This repository utilizes a **reusable GitHub Actions workflow** to automate the release process
using `semantic-release`. This setup ensures consistent and efficient releases across multiple
projects.

## Features

- **Automated Versioning:** Automatically determines the next version based on commit messages.
- **Changelog Generation:** Generates and updates the `CHANGELOG.md` with release notes.
- **Release Branching:** Creates dedicated release branches for each version.
- **Pull Request Automation:** Automatically creates a PR from the release branch to `main` for
review and merging.
- **Asset Attachment:** Attaches build artifacts to GitHub Releases.

## Setup Guide

Follow these steps to integrate the reusable release workflow into your project.

### 1. **Add Required Secrets**

Ensure that your repository has the necessary secrets configured:

1. **Navigate to Repository Settings:**

- Go to your repository on GitHub.
- Click on **Settings**.

2. **Add Secrets:**
- Go to **Secrets and variables** > **Actions** > **New repository secret**.
- Add the following secrets:
- `GH_TOKEN`: Your GitHub Personal Access Token with `repo` permissions.
- `PAT_FORCE_PUSH`: Your Personal Access Token with permissions to push to protected branches.

### 2. **Create the Reusable Workflow**

The reusable workflow is already defined in this repository at
`.github/workflows/reusable-release.yml`. If you're using this repository as the source, you can
skip this step. Otherwise, ensure that your reusable workflow is correctly defined and accessible.

### 3. **Create an Invoking Workflow**

Add a new workflow file in your repository to call the reusable release workflow.

**File Path:** `.github/workflows/call-reusable-release.yml`

**Content:**

```yaml
name: Call Reusable Release Workflow

on:
push:
branches:
- main

jobs:
release:
uses: @kurocado-studio/style-guide/.github/workflows/reusable-release.yml
with:
node-version: '18'
build-command: 'npm run build'
release-branch-prefix: 'release-'
release-label: 'release'
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PAT_FORCE_PUSH: ${{ secrets.PAT_FORCE_PUSH }}# Workflows
```
Loading

0 comments on commit eaf4db1

Please sign in to comment.