ci.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. name: CI
  2. on: ['push', 'pull_request']
  3. jobs:
  4. ci:
  5. name: CI
  6. runs-on: ubuntu-latest
  7. permissions:
  8. contents: write # to upload assets to releases
  9. attestations: write # to upload assets attestation for build provenance
  10. id-token: write # grant additional permission to attestation action to mint the OIDC token permission
  11. steps:
  12. - uses: actions/checkout@v4
  13. with:
  14. fetch-depth: 0
  15. - uses: actions/setup-python@v5
  16. with:
  17. python-version: '3.12'
  18. cache: 'pip'
  19. - uses: actions/setup-node@v4
  20. with:
  21. node-version: 'lts/*'
  22. cache: 'npm'
  23. - name: Set up PR environment
  24. if: github.event.number != null
  25. run: echo "PULL_REQUEST_ID=${{ github.event.number }}" >> $GITHUB_ENV
  26. - name: Install npm dependencies
  27. run: npm ci
  28. - name: Install pip dependencies
  29. run: pip install -r requirements.txt -r scripts/pdf/requirements.txt -r scripts/test-requirements.txt
  30. - name: Test
  31. run: npm test
  32. - name: Build
  33. run: bash scripts/build.sh
  34. - name: Build PDF
  35. if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
  36. working-directory: ./scripts/pdf
  37. run: bash build-pdf.sh
  38. - name: Deploy
  39. if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
  40. run: bash scripts/deploy.sh
  41. env:
  42. DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
  43. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  44. - name: Check for generated files
  45. if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
  46. id: check-files
  47. run: |
  48. if [[ -n $(find language_archives -name "*.zip" -print -quit) ]]; then
  49. echo "zip_exists=true" >> $GITHUB_ENV
  50. else
  51. echo "zip_exists=false" >> $GITHUB_ENV
  52. fi
  53. if [[ -n $(find scripts/pdf -name "*.pdf" -print -quit) ]]; then
  54. echo "pdf_exists=true" >> $GITHUB_ENV
  55. else
  56. echo "pdf_exists=false" >> $GITHUB_ENV
  57. fi
  58. if [[ -f tldr.sha256sums ]]; then
  59. echo "checksums_exist=true" >> $GITHUB_ENV
  60. else
  61. echo "checksums_exist=false" >> $GITHUB_ENV
  62. fi
  63. - name: Construct subject-path for attest
  64. if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
  65. id: construct-subject-path
  66. run: |
  67. subject_path=""
  68. if [[ ${{ env.zip_exists }} == 'true' ]]; then
  69. zip_files=$(find language_archives -name '*.zip' -printf '%p,')
  70. subject_path+="${zip_files::-1}"
  71. fi
  72. if [[ ${{ env.pdf_exists }} == 'true' ]]; then
  73. if [[ -n $subject_path ]]; then subject_path+=","; fi
  74. pdf_files=$(find scripts/pdf -name '*.pdf' -printf '%p,')
  75. subject_path+="${pdf_files::-1}"
  76. fi
  77. if [[ ${{ env.checksums_exist }} == 'true' ]]; then
  78. if [[ -n $subject_path ]]; then subject_path+=","; fi
  79. subject_path+='tldr.sha256sums'
  80. fi
  81. echo "subject_path=$subject_path" >> $GITHUB_ENV
  82. - name: Attest generated files
  83. if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
  84. id: attest
  85. uses: actions/attest-build-provenance@v2
  86. continue-on-error: true # prevent failing when no pages are modified
  87. with:
  88. subject-path: ${{ env.subject_path }}