|
| 1 | +--- |
| 2 | +name: Build Jekyll |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + site_artifact: |
| 8 | + description: 'Artifact name to download' |
| 9 | + required: false |
| 10 | + default: '' |
| 11 | + type: string |
| 12 | + extract_archive: |
| 13 | + description: | |
| 14 | + Name of nested archive to extract. In some cases you may want to upload a zip of files to reduce |
| 15 | + upload size and time. If you do this, you must specify the name of the archive to extract. |
| 16 | + required: false |
| 17 | + default: '' |
| 18 | + type: string |
| 19 | + config_file: |
| 20 | + description: 'Configuration file to use, relative to the site source directory' |
| 21 | + required: false |
| 22 | + default: '_config.yml' |
| 23 | + type: string |
| 24 | + target_branch: |
| 25 | + description: 'Branch to deploy to. Branch must already exist.' |
| 26 | + required: false |
| 27 | + default: 'gh-pages' |
| 28 | + type: string |
| 29 | + clean_gh_pages: |
| 30 | + description: 'Clean gh-pages before deploying' |
| 31 | + required: false |
| 32 | + default: true |
| 33 | + type: boolean |
| 34 | + theme_ref: |
| 35 | + description: 'Branch, tag, or commit SHA of the theme repository to use' |
| 36 | + required: false |
| 37 | + default: 'master' |
| 38 | + type: string |
| 39 | + secrets: |
| 40 | + GH_BOT_EMAIL: |
| 41 | + description: 'Email address of the bot account' |
| 42 | + required: true |
| 43 | + GH_BOT_NAME: |
| 44 | + description: 'Name of the bot account' |
| 45 | + required: true |
| 46 | + GH_BOT_TOKEN: |
| 47 | + description: 'Personal access token of the bot account' |
| 48 | + required: true |
| 49 | + |
| 50 | +jobs: |
| 51 | + build: |
| 52 | + name: Build Jekyll |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - name: Input validation |
| 56 | + run: | |
| 57 | + error=false |
| 58 | + if [ "${{ inputs.site_artifact }}" == 'site' ]; then |
| 59 | + echo "Artifact name cannot be 'site'" |
| 60 | + error=true |
| 61 | + fi |
| 62 | +
|
| 63 | + if [ "$error" = true ]; then |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Checkout theme |
| 68 | + uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + repository: LizardByte/LizardByte.github.io |
| 71 | + ref: ${{ github.repository == 'LizardByte/LizardByte.github.io' && github.ref || inputs.theme_ref }} |
| 72 | + submodules: recursive |
| 73 | + path: theme |
| 74 | + |
| 75 | + - name: Download input artifact |
| 76 | + if: ${{ inputs.site_artifact != '' }} |
| 77 | + uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: ${{ inputs.site_artifact }} |
| 80 | + path: project |
| 81 | + |
| 82 | + - name: Extract archive |
| 83 | + if: ${{ inputs.site_artifact != '' && inputs.extract_archive != '' }} |
| 84 | + working-directory: project |
| 85 | + run: | |
| 86 | + case "${{ inputs.extract_archive }}" in |
| 87 | + *.tar.gz|*.tgz) |
| 88 | + tar -xzf ${{ inputs.extract_archive }} -C . |
| 89 | + ;; |
| 90 | + *.tar) |
| 91 | + tar -xf ${{ inputs.extract_archive }} -C . |
| 92 | + ;; |
| 93 | + *.zip) |
| 94 | + unzip ${{ inputs.extract_archive }} -d . |
| 95 | + ;; |
| 96 | + *) |
| 97 | + echo "Unsupported archive format" |
| 98 | + exit 1 |
| 99 | + ;; |
| 100 | + esac |
| 101 | + rm -f ${{ inputs.extract_archive }} |
| 102 | +
|
| 103 | + - name: Setup project |
| 104 | + if: ${{ github.repository == 'LizardByte/LizardByte.github.io' }} |
| 105 | + run: | |
| 106 | + mkdir -p ./project |
| 107 | + cp -RT ./theme/ ./project/ |
| 108 | + rm -rf ./project/third-party |
| 109 | +
|
| 110 | + - name: Create site |
| 111 | + env: |
| 112 | + TMPDIR: /home/runner/work/tmp |
| 113 | + run: | |
| 114 | + mkdir -p ${TMPDIR} |
| 115 | +
|
| 116 | + base_dirs=( |
| 117 | + ./theme/third-party/beautiful-jekyll |
| 118 | + ./theme |
| 119 | + ) |
| 120 | +
|
| 121 | + targets=( |
| 122 | + *.gemspec |
| 123 | + _data |
| 124 | + _includes |
| 125 | + _layouts |
| 126 | + _sass |
| 127 | + assets |
| 128 | + 404.html |
| 129 | + _config_theme.yml |
| 130 | + favicon.ico |
| 131 | + feed.xml |
| 132 | + Gemfile |
| 133 | + staticman.yml |
| 134 | + tags.html |
| 135 | + ) |
| 136 | +
|
| 137 | + for base_dir in "${base_dirs[@]}"; do |
| 138 | + for target in "${targets[@]}"; do |
| 139 | + if [ -e "$base_dir/$target" ]; then |
| 140 | + cp -rf "$base_dir/$target" ${TMPDIR}/ |
| 141 | + fi |
| 142 | + done |
| 143 | + done |
| 144 | +
|
| 145 | + # copy project directory, they should only come from the project repo |
| 146 | + cp -RTf ./project/ ${TMPDIR}/ |
| 147 | +
|
| 148 | + # remove the workspace |
| 149 | + cd .. |
| 150 | + rm -rf ${GITHUB_WORKSPACE} |
| 151 | +
|
| 152 | + # move the temporary directory to the workspace |
| 153 | + mv ${TMPDIR} ${GITHUB_WORKSPACE} |
| 154 | + cd ${GITHUB_WORKSPACE} |
| 155 | +
|
| 156 | + # debug contents recursively |
| 157 | + ls -Ra |
| 158 | +
|
| 159 | + - name: Setup Ruby |
| 160 | + uses: ruby/setup-ruby@v1 |
| 161 | + with: |
| 162 | + ruby-version: '3.3' |
| 163 | + |
| 164 | + - name: Install dependencies |
| 165 | + run: | |
| 166 | + bundle install |
| 167 | +
|
| 168 | + - name: Setup Pages |
| 169 | + id: configure-pages |
| 170 | + uses: actions/configure-pages@v5 |
| 171 | + |
| 172 | + - name: Setup CI config |
| 173 | + run: | |
| 174 | + echo "---" > _config_ci.yml |
| 175 | + echo "baseurl: ${{ steps.configure-pages.outputs.base_path }}" >> _config_ci.yml |
| 176 | +
|
| 177 | + - name: Build site |
| 178 | + env: |
| 179 | + JEKYLL_ENV: production |
| 180 | + PAGES_REPO_NWO: ${{ github.repository }} |
| 181 | + run: | |
| 182 | + # if inputs.config_file exists |
| 183 | + config_files="_config_ci.yml,_config_theme.yml" |
| 184 | + if [ -e "${{ inputs.config_file }}" ]; then |
| 185 | + config_files="${config_files},${{ inputs.config_file }}" |
| 186 | + fi |
| 187 | +
|
| 188 | + bundle exec jekyll build --future --config ${config_files} |
| 189 | +
|
| 190 | + - name: Upload artifact |
| 191 | + uses: actions/upload-artifact@v4 |
| 192 | + with: |
| 193 | + name: site |
| 194 | + path: _site |
| 195 | + if-no-files-found: error |
| 196 | + include-hidden-files: true |
| 197 | + retention-days: 1 |
| 198 | + |
| 199 | + deploy: |
| 200 | + name: Deploy to Pages |
| 201 | + if: >- |
| 202 | + (github.event_name == 'push' && github.ref == 'refs/heads/master') || |
| 203 | + (github.event_name == 'schedule') || |
| 204 | + (github.event_name == 'workflow_dispatch') |
| 205 | + runs-on: ubuntu-latest |
| 206 | + needs: build |
| 207 | + steps: |
| 208 | + - name: Checkout gh-pages |
| 209 | + uses: actions/checkout@v4 |
| 210 | + with: |
| 211 | + ref: ${{ inputs.target_branch }} |
| 212 | + path: gh-pages |
| 213 | + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token |
| 214 | + fetch-depth: 0 # otherwise, will fail to push refs to dest repo |
| 215 | + |
| 216 | + - name: Clean |
| 217 | + if: ${{ inputs.clean_gh_pages }} |
| 218 | + run: | |
| 219 | + # empty contents of gh-pages |
| 220 | + rm -f -r ./gh-pages/* |
| 221 | +
|
| 222 | + - name: Download artifact |
| 223 | + uses: actions/download-artifact@v4 |
| 224 | + with: |
| 225 | + name: site |
| 226 | + path: gh-pages |
| 227 | + |
| 228 | + - name: no-jekyll |
| 229 | + run: | |
| 230 | + touch gh-pages/.nojekyll |
| 231 | +
|
| 232 | + - name: Deploy to gh-pages |
| 233 | + uses: actions-js/[email protected] |
| 234 | + with: |
| 235 | + github_token: ${{ secrets.GH_BOT_TOKEN }} |
| 236 | + author_email: ${{ secrets.GH_BOT_EMAIL }} |
| 237 | + author_name: ${{ secrets.GH_BOT_NAME }} |
| 238 | + directory: gh-pages |
| 239 | + branch: ${{ inputs.target_branch }} |
| 240 | + force: false |
| 241 | + message: "Deploy site from ${{ github.sha }}" |
0 commit comments