From 50e2f2e6ce8e82ae8b81ff24688dbb4824ca09a0 Mon Sep 17 00:00:00 2001 From: Dave Kerr Date: Wed, 30 Sep 2020 14:32:55 +0800 Subject: build: release ebook when version tag is pushed --- .github/workflows/build-on-pull-request.yaml | 38 +++++++++++++++++ .github/workflows/release-on-tag.yaml | 64 ++++++++++++++++++++++++++++ assets/ebook.sh | 40 ----------------- scripts/prepare-markdown-for-ebook.sh | 33 ++++++++++++++ 4 files changed, 135 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/build-on-pull-request.yaml create mode 100644 .github/workflows/release-on-tag.yaml delete mode 100755 assets/ebook.sh create mode 100755 scripts/prepare-markdown-for-ebook.sh diff --git a/.github/workflows/build-on-pull-request.yaml b/.github/workflows/build-on-pull-request.yaml new file mode 100644 index 0000000..dd3f17a --- /dev/null +++ b/.github/workflows/build-on-pull-request.yaml @@ -0,0 +1,38 @@ +# This pipeline builds the PDF ebook on any pull request to master. +name: "Build PDF" +on: + pull_request: + branches: + - master + +jobs: + prepare-pdf: + # Focal Fossa. Please don't use 'latest' tags, it's an anti-pattern. + runs-on: ubuntu-20.04 + steps: + # Checkout the code. + - name: Checkout + uses: actions/checkout@v2 + + # Prepare the content files. + - name: Prepare Content + run: ./scripts/prepare-markdown-for-ebook.sh + + # Create a PDF from the prepared markdown. + - name: Prepare PDF + uses: docker://pandoc/latex:2.9 + with: + args: "-V toc-title:\"Table Of Contents\" --toc --pdf-engine=pdflatex --standalone --output hacker-laws.pdf hacker-laws.md" + + # Publish the PDF and intermediate markdown as an artifact. + - name: Publish PDF Artifact + uses: actions/upload-artifact@master + with: + name: hacker-laws.pdf + path: hacker-laws.pdf + + - name: Publish Intermiediate Markdown Artifact + uses: actions/upload-artifact@master + with: + name: hacker-laws.md + path: hacker-laws.md diff --git a/.github/workflows/release-on-tag.yaml b/.github/workflows/release-on-tag.yaml new file mode 100644 index 0000000..722ec3d --- /dev/null +++ b/.github/workflows/release-on-tag.yaml @@ -0,0 +1,64 @@ +# This pipeline builds the PDF ebook on any tag starting with 'v'. +name: "Create Release" +on: + push: + tags: + - 'v*' + +jobs: + prepare-pdf: + # Focal Fossa. Please don't use 'latest' tags, it's an anti-pattern. + runs-on: ubuntu-20.04 + steps: + # Checkout the code. + - name: Checkout + uses: actions/checkout@v2 + + # Prepare the content files. + - name: Prepare Content + run: ./scripts/prepare-markdown-for-ebook.sh + + # Create a PDF from the prepared markdown. + - name: Prepare PDF + uses: docker://pandoc/latex:2.9 + with: + args: "-V toc-title:\"Table Of Contents\" --toc --pdf-engine=pdflatex --standalone --output hacker-laws.pdf hacker-laws.md" + + # Publish the PDF artifact. + - name: Publish PDF Artifacts + uses: actions/upload-artifact@master + with: + name: hacker-laws.pdf + path: hacker-laws.pdf + + release: + needs: prepare-pdf + runs-on: ubuntu-20.04 + steps: + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: hacker-laws.pdf + + - name: Create Release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + Hacker Laws E-Book + draft: false + prerelease: false + + - name: Upload 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: ./hacker-laws.pdf + asset_name: hacker-laws.pdf + asset_content_type: application/pdf diff --git a/assets/ebook.sh b/assets/ebook.sh deleted file mode 100755 index 18c25fd..0000000 --- a/assets/ebook.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# -# Requirements: -# - pandoc -# - xelatex -# brew install -# brew cask install basictex - -# Create the frontmatter. -cat << EOF > frontmatter.md ---- -title: "Hacker Laws" -author: "Dave Kerr, github.com/dwmkerr/hacker-laws" -subtitle: "Laws, Theories, Principles and Patterns that developers will find useful." ---- -EOF - -# Combine the frontmatter and the laws. -cat frontmatter.md README.md >> hacker-laws.md - -# Remove the title - we have it in the front-matter of the doc, so it will -# automatically be added to the PDF. -sed -i '' '/💻📖.*/d' hacker-laws.md - -# We can't have emojis in the final content with the PDF generator we're using. -sed -i '' 's/❗/Warning/' hacker-laws.md - -# Now rip out the translations line. -sed -i '' '/^\[Translations.*/d' hacker-laws.md - -# # Now rip out any table of contents items. -sed -i '' '/\*.*/d' hacker-laws.md -sed -i '' '/ \*.*/d' hacker-laws.md - -# Delete everything from 'Translations' onwards (we don't need the translations -# lists, related projects, etc). -sed -i ' ' '/## Translations/,$d' hacker-laws.md - -# Now build the e-book as a PDF. -pandoc -V toc-title:"Table Of Contents" --toc --pdf-engine=pdflatex -s -o hacker-laws.pdf hacker-laws.md diff --git a/scripts/prepare-markdown-for-ebook.sh b/scripts/prepare-markdown-for-ebook.sh new file mode 100755 index 0000000..172fd3e --- /dev/null +++ b/scripts/prepare-markdown-for-ebook.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# This script prepares a `hacker-laws.md` file which is in a format ready to be +# exported to PDF or other formats for an e-book. + +# Create the frontmatter. +cat << EOF > frontmatter.md +--- +title: "Hacker Laws" +author: "Dave Kerr, github.com/dwmkerr/hacker-laws" +subtitle: "Laws, Theories, Principles and Patterns that developers will find useful." +--- +EOF + +# Combine the frontmatter and the laws. +cat frontmatter.md README.md >> hacker-laws.md + +# Remove the title - we have it in the front-matter of the doc, so it will +# automatically be added to the PDF. +sed -i'' '/💻📖.*/d' hacker-laws.md + +# We can't have emojis in the final content with the PDF generator we're using. +sed -i'' 's/❗/Warning/' hacker-laws.md + +# Now rip out the translations line. +sed -i'' '/^\[Translations.*/d' hacker-laws.md + +# # Now rip out any table of contents items. +sed -i'' '/\*.*/d' hacker-laws.md +sed -i'' '/ \*.*/d' hacker-laws.md + +# Delete everything from 'Translations' onwards (we don't need the translations +# lists, related projects, etc). +sed -i'' '/## Translations/,$d' hacker-laws.md -- cgit v1.2.3