如何在 GitHub 操作中访问 GitHub 存储库的根目录?
How do I access the root of the GitHub Repository in a GitHub action?
我正在尝试从我的简历 repository 文件中的 resume.tex
构建一个简历 pdf,每当提交时。
我收到以下错误。
Error: File '/home/runner/work/resume/resume/resume.tex' cannot be found from the directory '/github/workspace'.
我应该如何访问 resume.tex
文件?如果我只说root_file: resume.tex
,错误是:
Error: File 'resume.tex' cannot be found from the directory '/github/workspace'.
.github/workflows/build_resume.yml
文件如下所示。 resume.tex
文件在我的 repository.
的根目录中
# This is a basic workflow to help you get started with Actions
name: Build PDF on commit.
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Github Action for LaTeX
uses: xu-cheng/latex-action@v2
with:
# The root LaTeX file to be compiled
root_file: ${{ github.workspace }}/resume.tex
# Interpret the root_file input as bash glob pattern
# glob_root_file: # optional
# The working directory for this action
# working_directory: # optional
# The LaTeX engine to be invoked
# compiler: # optional, default is latexmk
# Extra arguments to be passed to the LaTeX engine
# args: # optional, default is -pdf -file-line-error -halt-on-error -interaction=nonstopmode
# [Deprecated] Install extra packages by tlmgr
# extra_packages: # optional
# Install extra packages by apk
# extra_system_packages: # optional
# Install extra .ttf/.otf fonts.
# extra_fonts: ./fonts/*.ttf
# Arbitrary bash codes to be executed before compiling LaTeX documents
pre_compile: tlmgr update --self && tlmgr update --all
# Arbitrary bash codes to be executed after compiling LaTeX documents
post_compile: latexmk -c
# Instruct latexmk to enable --shell-escape
# latexmk_shell_escape: # optional
# Instruct latexmk to use LuaLaTeX
# latexmk_use_lualatex: # optional
# Instruct latexmk to use XeLaTeX
latexmk_use_xelatex: true
当你想从当前存储库执行文件时,你需要先使用actions/checkout(在你的作业步骤的开始)。
这将允许您在工作流程中访问存储库 $github_workspace
(Github environment variables 之一)。
注意:使用 action/checkout
后 运行 的所有命令都将在存储库根目录下执行。
例如,考虑到您的 resume.tex
文件位于存储库的根目录中,您可以使用如下内容:
name: Example
on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v2.3.4
- name: show resume.tex file content
run: cat resume.tex
Here 是来自个人存储库的另一个工作流示例,如果您想在工作流中执行位于存储库中的特定脚本,则遵循相同的逻辑。执行任何操作。
如果有人想做同样的事情,则需要完成以下步骤。
- 进入您的存储库。
- 使用xu-cheng/latex-action@v2
编译latex文档
- 检查是否生成PDF。
- 将 PDF 推送到存储库。
执行此操作的配置文件如下所示。
name: Github Actions CI to build pdf from tex source.
on: push
jobs:
build:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v2
with:
# The root LaTeX file to be compiled
root_file: resume_aditya_wagh.tex
# Interpret the root_file input as bash glob pattern
# glob_root_file: # optional
# The working directory for this action
# working_directory: # optional
# The LaTeX engine to be invoked
# compiler: # optional, default is latexmk
# Extra arguments to be passed to the LaTeX engine
args: -pdf -file-line-error -halt-on-error -interaction=nonstopmode
# Install extra packages by apk
# extra_system_packages: # optional
# Install extra .ttf/.otf fonts.
extra_fonts: ./fonts/*.ttf
# Arbitrary bash codes to be executed before compiling LaTeX documents
pre_compile: tlmgr update --self && tlmgr update --all
# Arbitrary bash codes to be executed after compiling LaTeX documents
post_compile: latexmk -c
# Instruct latexmk to enable --shell-escape
# latexmk_shell_escape: # optional
# Instruct latexmk to use LuaLaTeX
# latexmk_use_lualatex: # optional
# Instruct latexmk to use XeLaTeX
latexmk_use_xelatex: true
- name: Check pdf file
run: |
file resume_aditya_wagh.pdf | grep -q ' PDF '
- name: Upload file to repository
run: |
git config --global user.name "adityamwagh"
git config --global user.email "adityamwagh@gmail.com"
git add resume_aditya_wagh.pdf
git commit -m "commit message"
git push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
我正在尝试从我的简历 repository 文件中的 resume.tex
构建一个简历 pdf,每当提交时。
我收到以下错误。
Error: File '/home/runner/work/resume/resume/resume.tex' cannot be found from the directory '/github/workspace'.
我应该如何访问 resume.tex
文件?如果我只说root_file: resume.tex
,错误是:
Error: File 'resume.tex' cannot be found from the directory '/github/workspace'.
.github/workflows/build_resume.yml
文件如下所示。 resume.tex
文件在我的 repository.
# This is a basic workflow to help you get started with Actions
name: Build PDF on commit.
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Github Action for LaTeX
uses: xu-cheng/latex-action@v2
with:
# The root LaTeX file to be compiled
root_file: ${{ github.workspace }}/resume.tex
# Interpret the root_file input as bash glob pattern
# glob_root_file: # optional
# The working directory for this action
# working_directory: # optional
# The LaTeX engine to be invoked
# compiler: # optional, default is latexmk
# Extra arguments to be passed to the LaTeX engine
# args: # optional, default is -pdf -file-line-error -halt-on-error -interaction=nonstopmode
# [Deprecated] Install extra packages by tlmgr
# extra_packages: # optional
# Install extra packages by apk
# extra_system_packages: # optional
# Install extra .ttf/.otf fonts.
# extra_fonts: ./fonts/*.ttf
# Arbitrary bash codes to be executed before compiling LaTeX documents
pre_compile: tlmgr update --self && tlmgr update --all
# Arbitrary bash codes to be executed after compiling LaTeX documents
post_compile: latexmk -c
# Instruct latexmk to enable --shell-escape
# latexmk_shell_escape: # optional
# Instruct latexmk to use LuaLaTeX
# latexmk_use_lualatex: # optional
# Instruct latexmk to use XeLaTeX
latexmk_use_xelatex: true
当你想从当前存储库执行文件时,你需要先使用actions/checkout(在你的作业步骤的开始)。
这将允许您在工作流程中访问存储库 $github_workspace
(Github environment variables 之一)。
注意:使用 action/checkout
后 运行 的所有命令都将在存储库根目录下执行。
例如,考虑到您的 resume.tex
文件位于存储库的根目录中,您可以使用如下内容:
name: Example
on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v2.3.4
- name: show resume.tex file content
run: cat resume.tex
Here 是来自个人存储库的另一个工作流示例,如果您想在工作流中执行位于存储库中的特定脚本,则遵循相同的逻辑。执行任何操作。
如果有人想做同样的事情,则需要完成以下步骤。
- 进入您的存储库。
- 使用xu-cheng/latex-action@v2 编译latex文档
- 检查是否生成PDF。
- 将 PDF 推送到存储库。
执行此操作的配置文件如下所示。
name: Github Actions CI to build pdf from tex source.
on: push
jobs:
build:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v2
with:
# The root LaTeX file to be compiled
root_file: resume_aditya_wagh.tex
# Interpret the root_file input as bash glob pattern
# glob_root_file: # optional
# The working directory for this action
# working_directory: # optional
# The LaTeX engine to be invoked
# compiler: # optional, default is latexmk
# Extra arguments to be passed to the LaTeX engine
args: -pdf -file-line-error -halt-on-error -interaction=nonstopmode
# Install extra packages by apk
# extra_system_packages: # optional
# Install extra .ttf/.otf fonts.
extra_fonts: ./fonts/*.ttf
# Arbitrary bash codes to be executed before compiling LaTeX documents
pre_compile: tlmgr update --self && tlmgr update --all
# Arbitrary bash codes to be executed after compiling LaTeX documents
post_compile: latexmk -c
# Instruct latexmk to enable --shell-escape
# latexmk_shell_escape: # optional
# Instruct latexmk to use LuaLaTeX
# latexmk_use_lualatex: # optional
# Instruct latexmk to use XeLaTeX
latexmk_use_xelatex: true
- name: Check pdf file
run: |
file resume_aditya_wagh.pdf | grep -q ' PDF '
- name: Upload file to repository
run: |
git config --global user.name "adityamwagh"
git config --global user.email "adityamwagh@gmail.com"
git add resume_aditya_wagh.pdf
git commit -m "commit message"
git push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'