master <- develop #1212
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI-pr | |
env: | |
GO_VERSION: 1.21.3 | |
TZ: Asia/Tokyo | |
DOCS_TARXZ: docs.tar.xz | |
on: | |
pull_request: | |
branches: [develop, master, release, draft] | |
types: [synchronize, opened, reopened, ready_for_review] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
permissions: | |
repository-projects: read | |
outputs: | |
target_ref: ${{ steps.build.outputs.target_ref }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
ref: ${{ github.head_ref }} | |
- name: Site generator cache | |
uses: actions/cache@v4 | |
id: site-gen-cache | |
with: | |
path: ./site | |
key: site-gen-v3-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('src/**') }}-${{ hashFiles('app/**') }}-${{ hashFiles('docker/.env') }} | |
- name: Stack cache | |
if: steps.site-gen-cache.outputs.cache-hit != 'true' | |
uses: actions/cache@v4 | |
id: stack-cache | |
with: | |
path: ~/.stack | |
key: stack-v2-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('docker/.env') }} | |
- name: Get Haskell version | |
if: steps.site-gen-cache.outputs.cache-hit != 'true' | |
run: | | |
curl -sSLJ \ | |
"https://github.com/mikefarah/yq/releases/download/${{ env.yq_version }}/yq_linux_amd64.tar.gz" | | |
tar xzf - ./yq_linux_amd64 | |
chmod +x ./yq_linux_amd64 | |
echo "ghc_version=$(./yq_linux_amd64 '.compiler' ./stack.yaml | cut -f2 -d-)" >> "$GITHUB_ENV" | |
echo "stack_version=$(grep BOOTSTRAP_HASKELL_STACK_VERSION ./docker/.env | cut -f2 -d=)" >> "$GITHUB_ENV" | |
env: | |
yq_version: v4.44.3 | |
- name: Setup GHC | |
if: steps.site-gen-cache.outputs.cache-hit != 'true' | |
uses: haskell-actions/setup@v2 | |
with: | |
ghc-version: ${{ env.ghc_version }} | |
enable-stack: true | |
stack-version: ${{ env.stack_version }} | |
- name: Install tools (apt) | |
uses: awalsh128/cache-apt-pkgs-action@v1.4.2 | |
with: | |
packages: libxml2-utils parallel | |
version: 1.0 | |
- name: snap cache | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-snap-packages | |
with: | |
path: ~/snap | |
key: ${{ runner.os }}-snap-${{ env.cache-name }}-${{ hashFiles('**/snap-packages.txt') }} | |
restore-keys: | | |
${{ runner.os }}-snap-${{ env.cache-name }}- | |
${{ runner.os }}-snap- | |
${{ runner.os }}- | |
- name: Install tools (snap) | |
run: sudo snap install chromium | |
- name: Setup Stack | |
if: steps.site-gen-cache.outputs.cache-hit != 'true' && steps.stack-cache.outputs.cache-hit != 'true' | |
run: | | |
stack config set system-ghc --global true | |
stack config set install-ghc --global false | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Export values | |
run: | | |
echo "ROKI_WEB_GH_ACTIONS_NODE_VERSION=$(node --version)" >> "$GITHUB_ENV" | |
echo "PUPPETEER_EXECUTABLE_PATH=$(which chromium)" >> "$GITHUB_ENV" | |
- name: Node module cache | |
uses: actions/cache@v4 | |
id: node-cache | |
with: | |
path: '**/node_modules' | |
key: node-v1-${{ env.ROKI_WEB_GH_ACTIONS_NODE_VERSION }}-${{ runner.os }}-${{ hashFiles('.nvmrc') }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }} | |
- name: Install Node dependencies | |
if: steps.node-cache.outputs.cache-hit != 'true' | |
run: npm ci | |
env: | |
NPM_CONFIG_UPDATE_NOTIFIER: false | |
- name: Build the roki.dev generator | |
if: steps.site-gen-cache.outputs.cache-hit != 'true' | |
run: | | |
stack --local-bin-path . install --flag hakyll:-previewServer --flag hakyll:-watchServer | |
./site --version | |
- name: Docs cache | |
uses: actions/cache@v4 | |
id: docs-cache | |
with: | |
path: './docs' | |
key: docs-v1-${{ runner.os }} | |
- name: Build and validate roki.dev | |
id: build | |
run: | | |
for i in $(seq 0 ${{ env.RETRY_MAX }}); do | |
set +e -o pipefail | |
exec 3>&1 | |
site_out="$(./site build 2>&1 | tee /dev/fd/3)" | |
result=$? | |
exec 3>&- | |
set -e +o pipefail | |
if [ $result -eq 0 ]; then | |
break; | |
elif [ -n "$(grep "code: 'EAGAIN'" <<<"$site_out")" ]; then | |
echo "EAGAIN detected, try to run again (next count: $((i+1)))" >&2 | |
./site clean | |
continue; | |
else | |
exit 1 | |
fi | |
done | |
./site check --internal-links | |
parallel -I% --no-notice -j+0 --progress \ | |
xmllint docs/%/sitemap.xml docs/%/feed/%.xml --noout ::: ${{ env.TECH_BLOG }} ${{ env.DIARY_BLOG }} | |
tar cvf "${{ env.DOCS_TARXZ }}" docs | |
echo "target_ref=$(git show --format='%H' --no-patch)" >> "$GITHUB_OUTPUT" | |
env: | |
RETRY_MAX: 3 | |
TECH_BLOG: roki.log | |
DIARY_BLOG: roki.diary | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: roki.dev | |
path: ${{ env.DOCS_TARXZ }} | |
upload: | |
runs-on: ubuntu-latest | |
needs: build | |
outputs: | |
gdrive_path: ${{ steps.upload.outputs.gdrive_path }} | |
steps: | |
- name: Fetch archive | |
uses: actions/download-artifact@v4 | |
with: | |
name: roki.dev | |
- name: Skicka cache | |
uses: actions/cache@v4 | |
id: skicka-cache | |
with: | |
path: | | |
~/.go | |
~/.cache/go-build | |
~/.skicka.tokencache.json | |
~/.skicka.config | |
~/.skicka.metadata.cache | |
key: go-${{ env.GO_VERSION }}-v3-${{ runner.os }} | |
- name: Setup Go Path | |
run: | | |
echo "GOPATH=$HOME/.go" >> "$GITHUB_ENV" | |
echo "$HOME/.go/bin:$PATH" >> "$GITHUB_PATH" | |
- name: Setup Skicka | |
id: setup-skicka | |
if: steps.skicka-cache.outputs.cache-hit != 'true' | |
shell: bash | |
run: | | |
wget -q "https://dl.google.com/go/${{ env.GO_TARGZ }}" | |
tar -C "$HOME" -xzf "${{ env.GO_TARGZ }}" | |
mv "$HOME/go" "$HOME/.go" | |
go install github.com/google/skicka@latest | |
skicka init | |
echo -n "$SKICKA_TOKENCACHE_JSON" > "$HOME/.skicka.tokencache.json" | |
sed -i -e "s/;clientid=YOUR_GOOGLE_APP_CLIENT_ID/clientid=$GOOGLE_CLIENT_ID/g" "$HOME/.skicka.config" | |
sed -i -e "s/;clientsecret=YOUR_GOOGLE_APP_SECRET/clientsecret=$GOOGLE_CLIENT_SECRET/g" "$HOME/.skicka.config" | |
env: | |
SKICKA_TOKENCACHE_JSON: ${{ secrets.SKICKA_TOKENCACHE_JSON }} | |
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | |
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | |
GO_TARGZ: go${{ env.GO_VERSION }}.linux-amd64.tar.gz | |
- name: Setup variables | |
id: setup-variables | |
run: | | |
echo "repository_name=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> "$GITHUB_OUTPUT" | |
echo "docs_prefix=${{ env.DOCS_PREFIX }}" >> "$GITHUB_OUTPUT" | |
env: | |
DOCS_PREFIX: ${{ needs.build.outputs.target_ref }}-${{ github.run_number }} | |
- name: Upload to Google Drive | |
id: upload | |
run: | | |
echo "gdrive_path=${{ env.UPLOAD_GDRIVE_PATH }}" >> "$GITHUB_OUTPUT" | |
skicka -no-browser-auth upload -ignore-times "./${{ env.DOCS_TARXZ }}" "${{ env.UPLOAD_GDRIVE_PATH }}" | |
env: | |
UPLOAD_GDRIVE_PATH: CI_WORK/GitHubActions/${{ steps.setup-variables.outputs.repository_name }}/${{ steps.setup-variables.outputs.docs_prefix }}-${{ env.DOCS_TARXZ }} | |
boot-circle-ci: | |
runs-on: ubuntu-latest | |
needs: [build, upload] | |
steps: | |
- name: Set parameters | |
id: parameters | |
run: | | |
echo "enable_comment=$(test $ENAME = pull_request && echo true || echo false)" >> "$GITHUB_OUTPUT" | |
echo "target_branch=$(test $ENAME = pull_request && echo $HEAD_REF || echo $REF_NAME)" >> "$GITHUB_OUTPUT" | |
env: | |
ENAME: ${{ github.event_name }} | |
HEAD_REF: ${{ github.head_ref }} | |
REF_NAME: ${{ github.ref_name }} | |
- name: Boot CircleCI | |
id: boot-circleci | |
run: | | |
CIRCLE_RESP="$(curl -fsX POST -H "${{ env.CIRCLE_TOKEN }}" -H "${{ env.CONTENT_TYPE }}" -d '${{ env.DATA }}' "${{ env.ENDPOINT }}")" | |
readonly CIRCLE_RESP | |
echo "circle_job_num=$(jq -r .number <<< "$CIRCLE_RESP")" >> "$GITHUB_OUTPUT" | |
echo "created at: $(date -d "$(jq -r .created_at <<< "$CIRCLE_RESP")" +'%Y/%m/%d (%a) %T')" | |
env: | |
ENDPOINT: https://circleci.com/api/v2/project/gh/${{ github.repository }}/pipeline | |
CIRCLE_TOKEN: "Circle-Token: ${{ secrets.CIRCLE_API_USER_TOKEN }}" | |
CONTENT_TYPE: "Content-Type: application/json" | |
DATA: '{"branch":"${{ steps.parameters.outputs.target_branch }}", "parameters":{"TARGET_REF":"${{ needs.build.outputs.target_ref }}", "GDRIVE_PATH":"${{ needs.upload.outputs.gdrive_path }}","ENABLE_PR_COMMENT":${{ steps.parameters.outputs.enable_comment }}}}' | |
- name: Show CircleCI URL | |
run: echo ${{ env.CIRCLECI_URL }} | |
env: | |
CIRCLECI_URL: https://app.circleci.com/pipelines/github/${{ github.repository }}/${{ steps.boot-circleci.outputs.circle_job_num }} |