Repository navigation
Action (uses: 5ym/seisho@v1) として使えるようにし、テンプレートをやめる #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e07b77
変換を composite action (action.yml) にする
5ym f888125
Quarkdown が出力名の記号を置き換えても .qd と同じ名前の pdf にする
5ym d4a21fd
キャッシュから戻したときも Chrome の場所 (QD_CHROME_PATH) を渡す
5ym b94962e
テンプレートをやめ、Action として使う前提で説明を書き直す
5ym 4742fbe
チェックアウトしていない source-branch に対応し、続けて走ったときの push の競合を避ける
5ym ee26b9d
仕様の箇条書きを docs/spec.md に分け、README は使い方と書き方だけにする
5ym 987d97f
名前を seisho (清書) にし、md から移すスクリプトを消す
5ym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,85 +1,18 @@ | ||
| # このリポジトリの sample.qd で action.yml をそのまま試す | ||
| name: qd to pdf | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| branches: [master] | ||
|
|
||
| env: | ||
| QUARKDOWN_MAJOR: 2 | ||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: pdf | ||
|
|
||
| jobs: | ||
| convert: | ||
| pdf: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - name: git config and fetch branch | ||
| run: | | ||
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git config --local user.name "GitHub Action" | ||
| git config --global core.quotepath false | ||
| git fetch --no-tags --prune --depth=1 | ||
| - name: check branch exists and init and remove file and check modify | ||
| id: check | ||
| continue-on-error: true | ||
| run: | | ||
| (git checkout pdf && git fetch --unshallow origin pdf) || \ | ||
| (git checkout --orphan pdf && \ | ||
| git rm -rf . && echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904 > convertdone.txt && \ | ||
| git add . && git commit -m "first commit") | ||
| set -o pipefail | ||
| git diff --name-only --diff-filter=D `git show pdf:convertdone.txt` master | grep -E '\.qd$' | grep -v '\(^\|/\)_' | sed 's/\.[^.]*$//' | { while read -r f; do rm -f "$f.pdf"; done; } && \ | ||
| git add . && git commit -m "remove" | ||
| git diff --name-only --diff-filter=MAR `git show pdf:convertdone.txt` master | grep -E '\.qd$' | grep -v '\(^\|/\)_' >> modified.txt && \ | ||
| echo "status=success" >> $GITHUB_OUTPUT | ||
| - name: resolve quarkdown version | ||
| id: quarkdown | ||
| if: steps.check.outputs.status == 'success' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| tag=$(gh api "repos/iamgio/quarkdown/releases?per_page=100" \ | ||
| --jq "map(select(.draft == false and .prerelease == false and (.tag_name | startswith(\"v$QUARKDOWN_MAJOR.\")))) | .[0].tag_name") | ||
| if [ -z "$tag" ] || [ "$tag" = "null" ]; then | ||
| echo "quarkdown v$QUARKDOWN_MAJOR.x のリリースが見つかりません" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "version=${tag#v}" >> $GITHUB_OUTPUT | ||
| - name: cache quarkdown | ||
| id: quarkdown-cache | ||
| if: steps.check.outputs.status == 'success' | ||
| uses: actions/cache@v6 | ||
| with: | ||
| # 本体(JRE同梱)・puppeteer・Chromeが全てこの下に入る | ||
| path: ${{ runner.tool_cache }}/quarkdown | ||
| key: quarkdown-${{ runner.os }}-${{ steps.quarkdown.outputs.version }} | ||
| - name: install quarkdown | ||
| if: steps.check.outputs.status == 'success' && steps.quarkdown-cache.outputs.cache-hit != 'true' | ||
| uses: quarkdown-labs/setup-quarkdown@v1 | ||
| with: | ||
| quarkdown-version: ${{ steps.quarkdown.outputs.version }} | ||
| - name: use cached quarkdown | ||
| if: steps.check.outputs.status == 'success' && steps.quarkdown-cache.outputs.cache-hit == 'true' | ||
| run: | | ||
| # setup-quarkdownが作る/usr/local/binのラッパーはキャッシュ対象外なので同じ環境変数を張り直す | ||
| echo "$RUNNER_TOOL_CACHE/quarkdown/bin" >> $GITHUB_PATH | ||
| echo "QD_NPM_PREFIX=$RUNNER_TOOL_CACHE/quarkdown/lib" >> $GITHUB_ENV | ||
| echo "PUPPETEER_CACHE_DIR=$RUNNER_TOOL_CACHE/quarkdown/lib/puppeteer_cache" >> $GITHUB_ENV | ||
| - name: convert | ||
| if: steps.check.outputs.status == 'success' | ||
| run: | | ||
| git checkout master | ||
| git checkout -b tmp | ||
| # 元のフォルダ構造のままpdfを作る。--pdf-no-sandboxはubuntuランナーでは | ||
| # AppArmorによりChromeのsandboxが使えないため | ||
| while read -r f; do | ||
| quarkdown c "$f" --pdf --strict --allow global-read --pdf-no-sandbox \ | ||
| --out "$(dirname "$f")" --out-name "$(basename "${f%.*}")" | ||
| done < modified.txt | ||
| git add . && git commit -m "tmp" | ||
| git checkout pdf | ||
| git show tmp:modified.txt | sed 's/\.[^.]*$//' | xargs -i git checkout tmp {}.pdf | ||
| echo $GITHUB_SHA > convertdone.txt | ||
| git add . && git commit -m "convert" | ||
| - name: push | ||
| run: git push origin HEAD | ||
| - uses: ./ | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,82 +1,48 @@ | ||
| # paper | ||
| # seisho / 清書 | ||
|
|
||
| [Quarkdown](https://github.com/iamgio/quarkdown)でqdファイルをpdfに変換します。 | ||
| 清書。リポジトリの `.qd` を [Quarkdown](https://github.com/iamgio/quarkdown) で PDF にし、`pdf` ブランチへ置く GitHub Action。 | ||
|
|
||
| ## 仕様 | ||
| ## 使い方 | ||
|
|
||
| - 初回実行時はpdfブランチが自動で作成されます。(qdファイルが一つもなかった場合エラーで終了しブランチは作成されません。) | ||
| - theme等を変更し全てビルドしなおしたい時はpdfブランチ削除してmasterを変更すれば全てビルドしなおします。 | ||
| - 初回実行時qdファイルは再帰的に検索され全て変換されます。 | ||
| - 元々のファイルと同一のフォルダ構造で配置します。 | ||
| - pdfブランチにはpdfファイルのみを生成します。 | ||
| - masterからqdファイルを削除するとpdfからも自動で削除されます。 | ||
| - 変更があったファイルのみをビルドするようにしています。 | ||
| - リネームおよび移動した場合は旧ファイル名のpdfは残ります。 | ||
| - `_`で始まるファイル(`_setup.qd`など)は単体では変換されません。`.include`で読み込む共通設定や分割用のファイルはこの名前にしてください。 | ||
| - テーマ・用紙・フォントなどの共通設定は[_setup.qd](_setup.qd)にまとめてあります。文書の先頭で`.include {_setup.qd}`と書いて読み込んでください。([including other files](https://quarkdown.com/wiki/including-other-quarkdown-files/)) | ||
| - `_setup.qd`からの相対パスではなく、その文書から見た相対パスです。サブフォルダに置いた文書なら`.include {../_setup.qd}`になります。 | ||
| - `.include`の後に同じ関数を呼べばその文書だけ設定を上書きできます。 | ||
| - 変換対象は`.qd`のみです。mdから移行する場合は[md-to-qd.sh](md-to-qd.sh)を参照してください。 | ||
| - `--strict`を付けているので、未定義の関数呼び出しなど変換時のエラーがあればビルドを停止します。 | ||
| - ビルドは公式Action[`quarkdown-labs/setup-quarkdown`](https://github.com/quarkdown-labs/setup-quarkdown)でQuarkdown本体(JRE・PuppeteerとChromeを含む)を入れて実行します。バージョンは2系の最新リリースを自動で選びます。 | ||
| - インストール先(`$RUNNER_TOOL_CACHE/quarkdown`)を`actions/cache`でキャッシュしているので、バージョンが変わらない限り2回目以降のセットアップはダウンロード無しで済みます。 | ||
| - GitHub Actionsのubuntuランナーではpuppeteerが用意するChromeのsandboxがAppArmorで弾かれるため、CIでは`--pdf-no-sandbox`を付けています。手元で変換する場合は不要です。 | ||
| - PDFはHTMLをヘッドレスChromeで描画したものなのでLaTeXは不要です。 | ||
| - 文書の設定はファイル先頭の関数呼び出しで書きます。主な記法は[sample.qd](sample.qd)に一通り並べてあるので、そちらと[wiki](https://quarkdown.com/wiki/)を参照。 | ||
| - 種別: `.doctype {paged}` ([document types](https://quarkdown.com/wiki/document-types/)) | ||
| - 用紙: `.pageformat size:{A4} margin:{2cm}` ([page format](https://quarkdown.com/wiki/page-format/)) | ||
| - テーマ: `.theme {paperwhite} layout:{latex}` ([themes](https://quarkdown.com/wiki/themes/)) | ||
| - フォント: `.font {GoogleFonts:BIZ UDPMincho}` ([font configuration](https://quarkdown.com/wiki/font-configuration/)) | ||
| - 日本語フォントはQuarkdownに同梱されていないため、Google Fontsかリポジトリ内のフォントファイルを指定します。既定では`_setup.qd`で本文にBIZ UDPMincho、コードにM PLUS 1 Codeを指定しています。 | ||
| - コード用のフォントを別に指定しないと、`インラインコード`やコードブロック内の日本語が豆腐(□)になります。テーマ既定の等幅フォントに日本語が無いためです。 | ||
| - Mermaidの図は本文と別のフォントで描画されるため、図の中の日本語は表示されません。ラベルは英数字で書いてください。(図のキャプションは本文扱いなので日本語で書けます) | ||
| - その他機能追加,質問はissueでお願いします。 | ||
| ```yaml | ||
| # .github/workflows/pdf.yml | ||
| on: | ||
| push: | ||
| branches: [master] | ||
|
|
||
| ## プレビュー | ||
| permissions: | ||
| contents: write | ||
|
|
||
| Quarkdown本体のライブプレビューを使います。JRE同梱なのでJavaは不要です。(Node.jsが無ければ自動で入ります) | ||
| # 続けて push したときに pdf ブランチへの push がぶつからないように | ||
| concurrency: pdf | ||
|
|
||
| ```sh | ||
| curl -fsSL https://raw.githubusercontent.com/quarkdown-labs/get-quarkdown/refs/heads/main/install.sh | sudo env "PATH=$PATH" bash | ||
| jobs: | ||
| pdf: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - uses: 5ym/seisho@v1 | ||
| ``` | ||
|
|
||
| WSLで使う場合はWindows側ではなくWSL内にインストールします。他のインストール方法(Homebrew, Scoop等)は[本家のREADME](https://github.com/iamgio/quarkdown#getting-started)を参照。 | ||
|
|
||
| ```sh | ||
| quarkdown c sample.qd -w -p --allow global-read | ||
| ``` | ||
| | 入力 | 既定 | 内容 | | ||
| | --- | --- | --- | | ||
| | `source-branch` | push されたブランチ | `.qd` を読むブランチ | | ||
| | `pdf-branch` | `pdf` | PDF を置くブランチ。無ければ作る | | ||
| | `quarkdown-major` | `2` | この系列の最新リリースを使う | | ||
|
|
||
| `-w`が保存のたびに再コンパイル、`-p`がwebserver(既定で`localhost:8089`)を立ててブラウザを開き自動リロードします。`.doctype {paged}`はpaged.jsを使うのでwebserver越しでないと正しく表示されません。([CLI options](https://quarkdown.com/wiki/cli-options/)) | ||
| 動きの細かいところ (変換する範囲・消したときの扱い・作り直し方など) は [docs/spec.md](docs/spec.md) にまとめています。 | ||
|
|
||
| - `--allow global-read`はリポジトリ外・親ディレクトリのファイル(サブフォルダ文書からの`../_setup.qd`など)を読むために付けています。 | ||
| - ブラウザを開かずポートだけ使いたい場合は`-b none`、ポート変更は`--server-port`です。 | ||
| - PDFを手元で出したい場合は`quarkdown c sample.qd --pdf --strict --allow global-read`です。出力先は`quarkdown-output/`(`.gitignore`済み)なので、リポジトリを汚さずに確認できます。 | ||
| ## 書き方 | ||
|
|
||
| VS Codeの公式拡張[Quarkdown](https://marketplace.visualstudio.com/items?itemName=quarkdown.quarkdown-vscode)(`Ctrl+Shift+V`でプレビュー、`Ctrl+Alt+P`でPDF出力)も使えます。設定に以下を入れると`.include`や画像の読み込みで権限エラーになりません。 | ||
| 共通設定を `_setup.qd` に置き、各文書の先頭で読み込みます (パスはその文書から見た相対パス)。例は [_setup.qd](_setup.qd)、記法は [sample.qd](sample.qd) と [wiki](https://quarkdown.com/wiki/) を参照。 | ||
|
|
||
| ```json | ||
| { | ||
| "quarkdown.additionalCompilerOptions": "--allow global-read" | ||
| } | ||
| ```text | ||
| .include {_setup.qd} | ||
| ``` | ||
|
|
||
| `Quarkdown not found. Please install Quarkdown first.`と出る場合はインストールが済んでいないかPATHが通っていません。設定`quarkdown.path`に実行ファイルのパス(既定は`quarkdown`、install.shなら`/usr/local/bin/quarkdown`)を指定してください。VS CodeはWSLに接続した状態で使います。 | ||
|
|
||
| ## 使い方 | ||
|
|
||
| `Use this template`をクリックして新規リポジトリを作成してそこに`.qd`ファイルを追加していきます。 | ||
|
|
||
| ## mdからの移行 | ||
|
|
||
| 既にmdで書いている場合は[md-to-qd.sh](md-to-qd.sh)を一度実行すると全てqdに移行できます。(引数にファイルを渡すとそれだけ変換します) | ||
|
|
||
| ```sh | ||
| ./md-to-qd.sh | ||
| ``` | ||
| - 日本語フォントは同梱されていないので `.font` で指定します。コード用も指定しないと、コード中の日本語が豆腐になります。 | ||
| - Mermaid の図の中は日本語が出ません。ラベルは英数字で書いてください。 | ||
|
|
||
| - 先頭のYAMLフロントマターを取り除きます。(そのままだと`---`が区切り線、`title:`行が見出しとして本文に出てしまいます) | ||
| - その文書から見た相対パスで`.include {_setup.qd}`を先頭に足します。既に書いてある場合は足しません。 | ||
| - `_`で始まるファイルは分割用とみなして`.include`を足しません。 | ||
| - 元のmdは削除するので、結果を確認してからコミットしてください。`README.md`は対象外です。 | ||
| ## 手元で確認 | ||
|
|
||
| Quarkdown自体はMarkdownの上位互換なので、本文の書き方はほとんどそのままで通ります。ただし数式はQuarkdownの記法(`$ x $`のように前後に空白)のみ対応で、`\begin{equation}`やスペース無しの`$x$`はそのまま文字として出ます。 | ||
| [インストール](https://github.com/iamgio/quarkdown#getting-started)して `quarkdown c 文書.qd -w -p --allow global-read` でライブプレビュー、`--pdf` で PDF です。`--allow global-read` は `../_setup.qd` のような親ディレクトリのファイルを読むために要ります。VS Code なら公式拡張 [Quarkdown](https://marketplace.visualstudio.com/items?itemName=quarkdown.quarkdown-vscode) に `"quarkdown.additionalCompilerOptions": "--allow global-read"` を設定します。 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要確認:
uses: ./は、action が途中でpdfブランチへ切り替わるので、ローカル composite の post ステップ (actions/cacheの保存) がaction.ymlを作業ツリーから探して失敗するおそれがあります。pdfブランチにはaction.ymlがありません。PR の確認は5ym/paper@actionから呼ぶ形で行われているため、この./経由の経路は未検証に見えます。このワークフロー自体が緑になるか確かめてください。