【问题标题】:How do I access the root of the GitHub Repository in a GitHub action?如何在 GitHub 操作中访问 GitHub 存储库的根目录?
【发布时间】:2022-01-07 20:33:52
【问题描述】:

每当提交时,我都会尝试从简历 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

【问题讨论】:

    标签: pdf latex github-actions


    【解决方案1】:

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

    这将允许您在工作流程中访问存储库 $github_workspaceGithub 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 是来自个人存储库的另一个工作流示例,如果您想在工作流中执行位于存储库中的特定脚本,则遵循相同的逻辑。执行任何操作。

    【讨论】:

    • 感谢您的澄清。我现在想通了。
    【解决方案2】:

    如果有人希望这样做,则需要执行以下步骤。

    • 进入您的存储库。
    • 使用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'
    
    

    【讨论】:

      猜你喜欢
      • 2020-10-10
      • 2017-04-21
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多