Build a Jekyll site and create a release with the built site as an asset.

This workflow is triggered on push events to the default branch and can also be manually triggered.

Build

build

Release

release

Jekyll-build.yml

name: Build Jekyll

on:
  push:
    branches:
      - $default-branch
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.1"

      - name: Install Bundler
        run: |
          gem install bundler
          bundle install

      - name: Build Jekyll site
        run: |
          JEKYLL_ENV=production bundle exec jekyll build

      - name: Create Release
        id: create_release
        uses: actions/[email protected]
        env:
          GITHUB_TOKEN:  ${{ secrets.GITHUB_TOKEN }} 
        with:
          tag_name:  v${{ github.run_number }} 
          release_name:  Release ${{ github.run_number }} 

      - name: Zip _site directory
        run: zip -r _site.zip _site

      - name: Upload _site directory as release asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN:  ${{ secrets.GITHUB_TOKEN }} 
        with:
          upload_url:  ${{ steps.create_release.outputs.upload_url }} 
          asset_path: ./_site.zip
          asset_name: _site.zip
          asset_content_type: application/zip

GitHub Actions workflow file is used to build a Jekyll site and create a release with the built site as an asset.

  1. Checkout: This step checks out your repository so that your workflow can access the code.

  2. Setup Ruby: This step sets up Ruby environment using the setup-ruby action, specifying Ruby version 3.1.

  3. Install Bundler: This step installs Bundler, a Ruby gem manager, and then installs dependencies for your Jekyll project using bundle install.

  4. Build Jekyll site: This step builds your Jekyll site in production mode using the command bundle exec jekyll build. It sets the environment variable JEKYLL_ENV to production which is often used to configure Jekyll for different environments.

  5. Create Release: This step creates a GitHub release. It uses the create-release action, specifying the tag name as v${{ github.run_number }} and the release name as Release ${{ github.run_number }} .

  6. Zip _site directory: This step zips the _site directory where Jekyll generates the site content.

  7. Upload _site directory as release asset: This step uploads the zipped _site directory as a release asset using the upload-release-asset action. It specifies the upload URL from the previous step and provides the asset path, name, and content type.

Overall, this workflow automates the process of building a Jekyll site, creating a release, and uploading the built site as an asset to the release on GitHub.

More info ChatGPT Link