Skip to content

Update GitHub actions to the latest versions #115

Update GitHub actions to the latest versions

Update GitHub actions to the latest versions #115

name: Release Management
on:
push:
branches: [main]
jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-20.04
outputs:
version_changed: ${{ steps.check_package_version.outputs.changed }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Check package.json for version change
id: check_package_version
uses: EndBug/version-check@v2
- name: Log when version changed
if: steps.check_package_version.outputs.changed == 'true'
run: 'echo "Version change found in commit ${{ steps.check_package_version.outputs.commit }}! New version: ${{ steps.check_package_version.outputs.version }} (${{ steps.check_package_version.outputs.type }})"'
- name: Log when version unchanged
if: steps.check_package_version.outputs.changed == 'false'
run: 'echo "No version change"'
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: assets
path: assets/built
update_release_draft:
name: Update release draft
needs: [build_and_test]
if: needs.build_and_test.outputs.version_changed == 'false'
runs-on: ubuntu-20.04
steps:
- name: Draft release on GitHub
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_release_draft_on_version_bump:
name: Publish release draft
needs: [build_and_test]
if: needs.build_and_test.outputs.version_changed == 'true'
runs-on: ubuntu-20.04
steps:
- name: Clone repository
uses: actions/checkout@v4
# An existing release draft is published only if there is a version bump in `package.json`.
# Throws an error and breaks the job if called regardless. We check for version changes in the
# `build_and_test` job first so this job is skipped rather than exited with an error.
- name: Publish matching GitHub release draft
id: github_release
uses: JamesMGreene/node-draft-releaser@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
allow_release_name_update: 'false'
- name: Write out the release URL
run: echo "Released at $RELEASE_URL"
env:
RELEASE_URL: ${{ steps.github_release.outputs.release_url }}
deploy_theme:
name: Deploy theme to Ghost cloud
needs: [build_and_test, publish_release_draft_on_version_bump]
if: needs.build_and_test.outputs.version_changed == 'true'
runs-on: ubuntu-20.04
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: assets
path: assets/built
- name: Deploy Ghost theme
uses: TryGhost/action-deploy-theme@v1
with:
api-url: ${{ secrets.GHOST_ADMIN_API_URL }}
api-key: ${{ secrets.GHOST_ADMIN_API_KEY }}
exclude: '.* assets/scss/* dist/* postcss.config.js'