GithubActions powered blog and online CV
Tags: actionshackathon, jekyll, pandoc, devops
Published: 2020-08-14 11:47:38

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon, please fill out all sections.)
*My contribution to [GitHub Actions Hackathon on DEV](https://dev.to/devteam/announcing-the-github-actions-hackathon-on-dev-3ljn)*

This project is built on four powerful technologies:
- Jekyll - used as a static website generator
- Pandoc - used as a rendering tool (markdown > html) for CV
- Github Pages - used as a hosting
- GithubActions - used for build and deploy automation

### My Workflow
[Note]: # (Make sure to include the name of your GitHub Action and share where it's being used!)
There are two workflows: one for the blog (website), and one for the CV (cv). 
They both use the following Github Actions:
- [actions/checkout@v2](https://github.com/actions/checkout)
- [actions/upload-artifact@v2](https://github.com/actions/upload-artifact)
- [actions/download-artifact@v2](https://github.com/actions/download-artifact)

In both workflows, the build job is performed within a container, which is different per workflow: Ruby for the blog and Pandoc for CV.

Here is how the build job looks like for the blog:
```yaml
jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: ruby:2.6.4
      options: 
        --workdir /src 
    steps:
      - name: Checkout
        uses: actions/checkout@v2 

      - name: Build blog
        run: |
          bundle install
          bundle exec jekyll build --verbose --destination _site
      
      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with: 
          name: _site
          path: _site
```
As you can see, I run the steps within the Ruby container. This simplifies things related to file permissions and directory mounting because checkout is made inside the container.


The deploy step is performed via shell run command for now, for better clearness (can be replaced to third-party action or custom-made one): it makes a commit to `gh-pages` branch which is configured for Github Pages.
```yaml
  deploy:
    if: github.ref == 'refs/heads/master'
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout gh-pages branch
        uses: actions/checkout@v2
        with:
          ref: 'gh-pages'

      - name: Get the build artifact
        uses: actions/download-artifact@v2
        with:
          name: _site
          path: ./

      - name: Deploy (push) to gh-pages
        run: |
          git config user.name "$GITHUB_ACTOR"
          git config user.email "${GITHUB_ACTOR}@bots.github.com"
          git add -A 
          git commit -a -m "Updated Website"
          git remote set-url origin "https://x-access-token:${{ secrets.DEPLOY_TOKEN }}@github.com/vasylenko/serhii.vasylenko.info.git"
          git push --force-with-lease origin gh-pages
```

### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)
DIY Deployments

### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)
Here is a link to repository with workflows (see /.github/workflows directory)
{% github https://github.com/vasylenko/serhii.vasylenko.info %}


### Additional Resources / Info

https://jekyllrb.com
https://pandoc.org

[Reminder]: # (Submissions are due on September 12th (11:59 PM PDT) and winners will be announced on September 23!)