Build & deploy #139
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & deploy | |
on: | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Cache yarn packages | |
uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}" | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- if: steps.yarn-cache.outputs.cache-hit != 'true' | |
name: List the state of node modules | |
continue-on-error: true | |
run: yarn list | |
- name: Install dependencies | |
run: yarn install | |
- name: Build app | |
run: yarn build | |
- name: Upload app artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app-build | |
path: ./build | |
deploy: | |
name: Deploy | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Download app build | |
uses: actions/download-artifact@v4 | |
with: | |
name: app-build | |
path: ./build | |
- name: Deploy to GH Pages | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./build | |
create_release: | |
name: Release with Changelog | |
needs: deploy | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Get Next Version | |
id: semver | |
uses: ietf-tools/semver-action@v1 | |
with: | |
token: ${{ github.token }} | |
branch: main | |
patchAll: true | |
- name: Create tag | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{ steps.semver.outputs.next }}', | |
sha: context.sha | |
}) | |
- name: Update CHANGELOG | |
id: changelog | |
uses: requarks/changelog-action@v1 | |
with: | |
token: ${{ github.token }} | |
tag: ${{ steps.semver.outputs.next }} | |
excludeTypes: "build,docs,other" | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
draft: false | |
makeLatest: true | |
name: ${{ steps.semver.outputs.next }} | |
body: ${{ steps.changelog.outputs.changes }} | |
tag: ${{ steps.semver.outputs.next }} | |
commit: ${{ github.sha }} | |
token: ${{ github.token }} | |
- name: Commit CHANGELOG.md | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
branch: main | |
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]' | |
file_pattern: CHANGELOG.md |