如何在 GitHub 操作中访问 GitHub 存储库的根目录?

问题描述 投票:0回答:2

每当提交时,我都会尝试从简历

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
文件位于我的 存储库的根目录中。

# 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

pdf latex github-actions
2个回答
8
投票

当您想要从当前存储库执行文件时,您需要首先使用actions/checkout(在作业步骤的开始处)。

这将允许您在工作流程中访问存储库

$github_workspace
Github 环境变量之一)。

注意:使用

action/checkout
后运行的所有命令都将在存储库根目录中执行。

例如,考虑到您的

resume.tex
文件位于存储库的根目录,您将使用如下内容:

   name: Example

   on:
     push:
     pull_request:

   jobs:
    build:
      runs-on: ubuntu-latest
      steps:
      - name: checkout repo
        uses: actions/checkout@v4
      - name: show resume.tex file content
        run: cat resume.tex

这里是个人存储库中的另一个工作流示例,如果您想在工作流中执行位于存储库中的特定脚本,请遵循相同的逻辑。执行任何操作。


0
投票

如果有人想要做同样的事情,则需要执行以下步骤。

执行此操作的配置文件如下所示。

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 "[email protected]"
        git add resume_aditya_wagh.pdf
        git commit -m "commit message"
        git push
      if: github.event_name == 'push' && github.ref == 'refs/heads/main'

© www.soinside.com 2019 - 2024. All rights reserved.