-
-
Notifications
You must be signed in to change notification settings - Fork 2
124 lines (104 loc) · 4.81 KB
/
build.yml
File metadata and controls
124 lines (104 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Build Pipeline # A Build Pipeline which will use for build, test and deploy.
on:
push: # When we push the changes.
branches: # Only for these branches.
- master
- bugfix/*
- hotfix/*
- feature/*
- release/*
paths-ignore: # Ignoring the markdown file changes.
- '**/*.md'
pull_request: # Also on pull request events.
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab.
jobs:
build: # Job named 'build'
name: Build & Test
runs-on: ubuntu-latest # The type of machine to run the job on.
env:
DATABASE_URL: ${{ vars.DATABASE_URL }}
steps: # The sequence of tasks that make up a job.
- name: Checking out repository code
uses: actions/checkout@v4.2.2 # Action for checking out a repo.
- name: Setup Node.js Environment
uses: actions/setup-node@v4.4.0 # Action for setting up Node environment.
with:
node-version: latest
- name: Install PNPM package manager
uses: pnpm/action-setup@v4.1.0 # Action for setting up pnpm.
id: pnpm-install
with:
version: ^9
run_install: false
- name: Capture pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache pnpm Store
uses: actions/cache@v4.2.3 # Action provides caching dependencies and build outputs to improve workflow execution time.
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} # The path of the directory to cache.
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} # An explicit key for restoring and saving the cache.
restore-keys: |
${{ runner.os }}-pnpm-store-
# Installs all dependencies specified in the project's package.json file.
- name: Install dependencies using pnpm
run: pnpm install
# This compiles the application in optimized production mode and output it to the build folder.
- name: Build the application and export it
run: pnpm run build
# Runs unit tests for the application using Jest.
- name: Execute tests using Vitest
run: pnpm run test
release:
name: Create Release
# Specify the type of the runner the job will run on
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.ref_name == 'master' }}
# Set permissions to write contents
permissions:
contents: write
steps: # Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0 # Fetches all history for all branches and tags
# Generate a changelog for the new release using Git
- name: Generate a changelog
uses: orhun/git-cliff-action@v4.4.2
id: git-cliff
with:
config: cliff.toml # The configuration file for git-cliff
args: -vv --latest --strip all # Show verbose output, grab the latest changes, and strip unnecessary details
env:
OUTPUT: CHANGES.md # The output file for the changelog
# Prepare release notes by processing the generated changelog
- name: Set the release info
id: release
shell: bash
run: |
version=$(jq -r '.version' package.json)
echo "version=${version}" >> $GITHUB_OUTPUT
# Read contents of changelog into variable 'changelog_content'
changelog=$(cat ${{ steps.git-cliff.outputs.changelog }})
# Remove first two lines from 'changelog'
changelog="$(printf "$changelog" | tail -n +3)"
# Save the value of 'changelog' back into the GitHub environment output
{
echo "notes<<EOF"
echo "$changelog"
echo "EOF"
} >> $GITHUB_OUTPUT
# Create a new GitHub release using the gathered information
- name: Create the release
uses: nekofar/create-github-release@v1.0.14
with:
tag: v${{ steps.release.outputs.version }} # The name of the tag to be released
title: v${{ steps.release.outputs.version }} # The title for the release
notes: ${{ steps.release.outputs.notes }} # The release notes generated in the previous step
draft: true # The release will be created as a draft
prerelease: ${{ contains(steps.release.outputs.version, '-rc') || contains(steps.release.outputs.version, '-beta') || contains(steps.release.outputs.version, '-alpha') }} # Conditions to mark the release as a pre-release
concurrency: # Allows controlling the concurrency level of the job in the build pipeline.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # If enabled, previous runs of this workflow for the same group-key will be cancelled while this build or run is in progress.