Skip to content

Commit

Permalink
ci: refine Jekyll preview workflow
Browse files Browse the repository at this point in the history
Use PR ID in the URL instead of the hash
and build without Docker.
  • Loading branch information
link2xt committed Sep 3, 2023
1 parent 55b275a commit 5d70184
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 80 deletions.
104 changes: 59 additions & 45 deletions .github/workflows/jekyll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,66 @@ on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest

env:
GEM_HOME: ~/.gems

steps:
- name: Can we upload the preview? # Get Pullrequest ID
id: prepare
run: |
if [ $(expr length "${{ secrets.USERNAME }}") -gt "1" ]; then echo ::set-output name=uploadtoserver::true ;fi
- uses: actions/checkout@v1
- name: Fix lockfile permissions
run: |
chmod 666 Gemfile.lock
- name: Build the site in the jekyll/builder container
run: |
docker run \
-v ${{ github.workspace }}:/srv/jekyll -v ${{ github.workspace }}/_site:/srv/jekyll/_site \
jekyll/builder:latest /bin/bash -c "chmod 777 /srv/jekyll && jekyll build --future"
- name: Upload
if: steps.prepare.outputs.uploadtoserver
uses: appleboy/scp-action@master
with:
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
host: mailadm.testrun.org
port: 22
source: _site
target: providerOverview/${{ github.sha }}/
- name: "Post links to details"
if: steps.prepare.outputs.uploadtoserver
id: details
run: |
# URLs for API connection and uploads
export GITHUB_API_URL="https://api.github.com/repos/deltachat/provider-db/statuses/${{ github.event.after }}"
export PREVIEW_LINK="https://mailadm.testrun.org/provider/${{ github.sha }}/_site/"
# Post AppImage download link to check details
export STATUS_DATA="{\"state\": \"success\", \
\"description\": \"Preview the page here:\", \
\"context\": \"Page Preview\", \
\"target_url\": \"${PREVIEW_LINK}\"}"
export RESPONSE=$(curl -X POST --header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --url "$GITHUB_API_URL" --header "content-type: application/json" --data "$STATUS_DATA" | jq -r .message)
if [ "$RESPONSE" == "Not Found" ]; then echo ::set-output name=comment::true ;fi
- name: "Post link to comments"
if: steps.details.outputs.comment
uses: rytswd/[email protected]
with:
body: "Check out the page preview at https://mailadm.testrun.org/provider/${{ github.sha }}/_site/"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Pullrequest ID
id: prepare
run: |
PULLREQUEST_ID=$(echo "${{ github.ref }}" | cut -d "/" -f3)
echo "prid=$PULLREQUEST_ID" >> $GITHUB_OUTPUT
if test $(expr length "${{ secrets.USERNAME }}") -gt "1"; then
echo "uploadtoserver=true" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
- name: Install Bundler
run: sudo gem install bundler

- name: Cache bundle
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install Jekyll
run: bundle install

- name: Build the site with Jekyll
run: |
bundle exec jekyll build --future --baseurl "/${{ steps.prepare.outputs.prid }}"
mkdir ${{ steps.prepare.outputs.prid }}
- name: Upload preview
if: steps.prepare.outputs.uploadtoserver
run: |
mkdir -p "$HOME/.ssh"
echo "${{ secrets.KEY }}" > "$HOME/.ssh/key"
chmod 600 "$HOME/.ssh/key"
rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/_site/ "${{ secrets.USERNAME }}@mailadm.testrun.org:providerOverview/${{ steps.prepare.outputs.prid }}/"
- name: "Post links to details"
if: steps.prepare.outputs.uploadtoserver
id: details
run: |
# URLs for API connection and uploads
export GITHUB_API_URL="https://api.github.com/repos/deltachat/provider-db/statuses/${{ github.event.after }}"
export PREVIEW_LINK="https://mailadm.testrun.org/provider/${{ steps.prepare.outputs.prid }}/"
# Post AppImage download link to check details
export STATUS_DATA="{\"state\": \"success\", \
\"description\": \"Preview the page here:\", \
\"context\": \"Page Preview\", \
\"target_url\": \"${PREVIEW_LINK}\"}"
export RESPONSE=$(curl -X POST --header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --url "$GITHUB_API_URL" --header "content-type: application/json" --data "$STATUS_DATA" | jq -r .message)
if [ "$RESPONSE" == "Not Found" ]; then echo ::set-output name=comment::true ;fi
- name: "Post link to comments"
if: steps.details.outputs.comment
uses: rytswd/[email protected]
with:
body: "Check out the page preview at https://mailadm.testrun.org/provider/${{ steps.prepare.outputs.prid }}/"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 changes: 32 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.6)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.8.1)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.11.1)
colorator (1.1.0)
commonmarker (0.23.6)
concurrent-ruby (1.1.10)
dnsruby (1.61.9)
simpleidn (~> 0.1)
commonmarker (0.23.10)
concurrent-ruby (1.2.2)
dnsruby (1.70.0)
simpleidn (~> 0.2.1)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
ethon (0.15.0)
ethon (0.16.0)
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.8.1)
faraday (2.6.0)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.1)
faraday-net_http (3.0.2)
ffi (1.15.5)
forwardable-extended (2.6.0)
gemoji (3.0.1)
github-pages (227)
github-pages (228)
github-pages-health-check (= 1.17.9)
jekyll (= 3.9.2)
jekyll (= 3.9.3)
jekyll-avatar (= 0.7.0)
jekyll-coffeescript (= 1.1.1)
jekyll-commonmark-ghpages (= 0.2.0)
jekyll-commonmark-ghpages (= 0.4.0)
jekyll-default-layout (= 0.1.4)
jekyll-feed (= 0.15.1)
jekyll-gist (= 1.5.0)
Expand Down Expand Up @@ -71,7 +70,7 @@ GEM
jemoji (= 0.12.0)
kramdown (= 2.3.2)
kramdown-parser-gfm (= 1.1.0)
liquid (= 4.0.3)
liquid (= 4.0.4)
mercenary (~> 0.3)
minima (= 2.5.1)
nokogiri (>= 1.13.6, < 2.0)
Expand All @@ -87,13 +86,13 @@ GEM
activesupport (>= 2)
nokogiri (>= 1.4)
http_parser.rb (0.8.0)
i18n (0.9.5)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jekyll (3.9.2)
jekyll (3.9.3)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 0.7)
i18n (>= 0.7, < 2)
jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 2.0)
kramdown (>= 1.17, < 3)
Expand All @@ -109,11 +108,11 @@ GEM
coffee-script-source (~> 1.11.1)
jekyll-commonmark (1.4.0)
commonmarker (~> 0.22)
jekyll-commonmark-ghpages (0.2.0)
commonmarker (~> 0.23.4)
jekyll-commonmark-ghpages (0.4.0)
commonmarker (~> 0.23.7)
jekyll (~> 3.9.0)
jekyll-commonmark (~> 1.4.0)
rouge (>= 2.0, < 4.0)
rouge (>= 2.0, < 5.0)
jekyll-default-layout (0.1.4)
jekyll (~> 3.0)
jekyll-feed (0.15.1)
Expand Down Expand Up @@ -201,29 +200,29 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.3)
listen (3.7.1)
liquid (4.0.4)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
minima (2.5.1)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.16.3)
nokogiri (1.13.9-x86_64-linux)
minitest (5.19.0)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.7)
racc (1.6.0)
racc (1.7.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.5)
rexml (3.2.6)
rouge (3.26.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -240,23 +239,21 @@ GEM
unf (~> 0.1.4)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (1.2.10)
thread_safe (~> 0.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
zeitwerk (2.6.4)

PLATFORMS
x86_64-linux-musl
x86_64-linux

DEPENDENCIES
github-pages
jekyll-include-cache (~> 0.2.0)

BUNDLED WITH
2.3.23
2.4.13

0 comments on commit 5d70184

Please sign in to comment.