|
| 1 | +name: 'Build and Deploy LaTeX' |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + file_name: |
| 6 | + description: 'LaTeX root file name without extension, example: MyTeXFile' |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | + runs_on: |
| 11 | + description: 'Agent image' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | + workflow_name: |
| 16 | + description: 'Workflow name' |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + |
| 20 | + build_assets_path: |
| 21 | + description: 'Build assets path' |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + |
| 25 | + working_directory_for_latex: |
| 26 | + description: 'Working directory for LaTeX' |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + |
| 30 | +env: |
| 31 | + TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} |
| 32 | + USERNAME: "kolosovpetro" |
| 33 | + EMAIL: "kolosovp94@gmail.com" |
| 34 | + MESSAGE: "CICD deploy of ${{ inputs.file_name }} PDF document" |
| 35 | + |
| 36 | +jobs: |
| 37 | + build-pdf: |
| 38 | + runs-on: ${{ inputs.runs_on }} |
| 39 | + name: ${{ inputs.workflow_name }} |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: '🔎 Fetch sources 🔎' |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + - name: '⬇️ Install GitVersion ⬇️' |
| 48 | + uses: gittools/actions/gitversion/setup@v3.0.0 |
| 49 | + with: |
| 50 | + versionSpec: '5.x' |
| 51 | + preferLatestVersion: true |
| 52 | + |
| 53 | + - name: '🤔 Determine Version 🤔' |
| 54 | + uses: gittools/actions/gitversion/execute@v3.0.0 |
| 55 | + with: |
| 56 | + useConfigFile: true |
| 57 | + |
| 58 | + - name: '📜 Print Version 📜' |
| 59 | + run: | |
| 60 | + echo "SemVer: ${{ env.GitVersion_SemVer }}" |
| 61 | + echo "BranchName: ${{ env.GitVersion_BranchName }}" |
| 62 | + echo "ShortSha: ${{ env.GitVersion_ShortSha }}" |
| 63 | + newVersion="${{ env.GitVersion_SemVer }}+${{ env.GitVersion_BranchName }}.${{ env.GitVersion_ShortSha }}" |
| 64 | + echo "Next version: $newVersion" |
| 65 | +
|
| 66 | + - name: '🔄 Update version.tex 🔄' |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + newVersion="${{ env.GitVersion_SemVer }}+${{ env.GitVersion_BranchName }}.${{ env.GitVersion_ShortSha }}" |
| 70 | + sed -i "s|Local-0.1.0|$newVersion|" "src/sections/version.tex" |
| 71 | +
|
| 72 | + - name: '🛠 Build PDF 🛠' |
| 73 | + uses: xu-cheng/latex-action@v3 |
| 74 | + with: |
| 75 | + root_file: '${{ inputs.file_name }}.tex' |
| 76 | + working_directory: '${{ inputs.working_directory_for_latex }}' |
| 77 | + |
| 78 | + - name: '⬆️ Upload build assets ⬆️' |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: '${{ inputs.file_name }}-${{ env.GitVersion_InformationalVersion }}' |
| 82 | + path: '${{ inputs.build_assets_path }}' |
| 83 | + |
| 84 | + - name: '⬆️ Upload artifacts PDF ⬆️' |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: '${{ inputs.file_name }}-PDF-${{ env.GitVersion_InformationalVersion }}' |
| 88 | + path: '${{ inputs.working_directory_for_latex}}/${{ inputs.file_name }}.pdf' |
| 89 | + |
| 90 | + - name: '📀 Clone repository 📀' |
| 91 | + run: | |
| 92 | + git clone https://${{ env.TOKEN }}@github.com/kolosovpetro/kolosovpetro.github.io.git ~/kolosovpetro.github.io |
| 93 | + cp src/${{ inputs.file_name }}.pdf ~/kolosovpetro.github.io/pdf/${{ inputs.file_name }}.pdf |
| 94 | +
|
| 95 | + - name: '❇️ Commit changes ❇️' |
| 96 | + run: | |
| 97 | + cd ~/kolosovpetro.github.io |
| 98 | + git config --global user.name "${{ env.USERNAME }}" |
| 99 | + git config --global user.email "${{ env.EMAIL }}" |
| 100 | + git add . |
| 101 | + git commit -m "${{ env.MESSAGE }}" |
| 102 | + git push |
0 commit comments