2020-06-09 11:10:15 +01:00
|
|
|
name: CI
|
|
|
|
|
|
|
|
on: ['push', 'pull_request']
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
ci:
|
|
|
|
name: CI
|
2024-05-30 06:35:32 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: write # to upload assets to releases
|
|
|
|
attestations: write # to upload assets attestation for build provenance
|
|
|
|
id-token: write # grant additional permission to attestation action to mint the OIDC token permission
|
2020-06-09 11:10:15 +01:00
|
|
|
|
|
|
|
steps:
|
2023-09-05 15:29:38 +01:00
|
|
|
- uses: actions/checkout@v4
|
2023-11-11 18:35:12 +00:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2022-10-12 11:17:21 +01:00
|
|
|
|
2023-12-14 04:34:07 +00:00
|
|
|
- uses: actions/setup-python@v5
|
2021-09-03 16:17:51 +01:00
|
|
|
with:
|
2023-12-14 04:34:07 +00:00
|
|
|
python-version: '3.12'
|
2022-10-12 11:17:21 +01:00
|
|
|
cache: 'pip'
|
2020-06-09 11:10:15 +01:00
|
|
|
|
2023-11-01 09:23:38 +00:00
|
|
|
- uses: actions/setup-node@v4
|
2020-10-05 16:23:08 +01:00
|
|
|
with:
|
2022-10-12 11:17:21 +01:00
|
|
|
node-version: 'lts/*'
|
|
|
|
cache: 'npm'
|
2020-06-09 11:10:15 +01:00
|
|
|
|
2020-06-24 13:11:33 +01:00
|
|
|
- name: Set up PR environment
|
|
|
|
if: github.event.number != null
|
2020-11-18 11:54:26 +00:00
|
|
|
run: echo "PULL_REQUEST_ID=${{ github.event.number }}" >> $GITHUB_ENV
|
2020-06-24 13:11:33 +01:00
|
|
|
|
2020-06-09 11:10:15 +01:00
|
|
|
- name: Install npm dependencies
|
|
|
|
run: npm ci
|
|
|
|
|
2022-10-12 11:17:21 +01:00
|
|
|
- name: Install pip dependencies
|
2024-05-18 01:33:40 +01:00
|
|
|
run: pip install -r requirements.txt -r scripts/pdf/requirements.txt -r scripts/test-requirements.txt
|
2021-09-03 16:17:51 +01:00
|
|
|
|
2020-06-09 11:10:15 +01:00
|
|
|
- name: Test
|
|
|
|
run: npm test
|
|
|
|
|
|
|
|
- name: Build
|
|
|
|
run: bash scripts/build.sh
|
|
|
|
|
2020-11-27 09:27:13 +00:00
|
|
|
- name: Build PDF
|
2021-01-08 09:13:15 +00:00
|
|
|
if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
|
2022-10-12 11:17:21 +01:00
|
|
|
working-directory: ./scripts/pdf
|
2023-10-21 22:04:22 +01:00
|
|
|
run: bash build-pdf.sh
|
2020-11-27 09:27:13 +00:00
|
|
|
|
2020-06-09 11:10:15 +01:00
|
|
|
- name: Deploy
|
2021-01-08 09:13:15 +00:00
|
|
|
if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
|
2020-06-24 13:30:09 +01:00
|
|
|
run: bash scripts/deploy.sh
|
|
|
|
env:
|
|
|
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
2024-01-11 20:35:05 +00:00
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2024-05-30 06:35:32 +01:00
|
|
|
|
|
|
|
- name: Check for generated files
|
|
|
|
if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
|
|
|
|
id: check-files
|
|
|
|
run: |
|
|
|
|
if [[ -n $(find language_archives -name "*.zip" -print -quit) ]]; then
|
|
|
|
echo "zip_exists=true" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "zip_exists=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $(find scripts/pdf -name "*.pdf" -print -quit) ]]; then
|
|
|
|
echo "pdf_exists=true" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "pdf_exists=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f tldr.sha256sums ]]; then
|
|
|
|
echo "checksums_exist=true" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "checksums_exist=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Construct subject-path for attest
|
|
|
|
if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
|
|
|
|
id: construct-subject-path
|
|
|
|
run: |
|
|
|
|
subject_path=""
|
|
|
|
if [[ ${{ env.zip_exists }} == 'true' ]]; then
|
|
|
|
zip_files=$(find language_archives -name '*.zip' -printf '%p,')
|
|
|
|
subject_path+="${zip_files::-1}"
|
|
|
|
fi
|
|
|
|
if [[ ${{ env.pdf_exists }} == 'true' ]]; then
|
|
|
|
if [[ -n $subject_path ]]; then subject_path+=","; fi
|
|
|
|
pdf_files=$(find scripts/pdf -name '*.pdf' -printf '%p,')
|
|
|
|
subject_path+="${pdf_files::-1}"
|
|
|
|
fi
|
|
|
|
if [[ ${{ env.checksums_exist }} == 'true' ]]; then
|
|
|
|
if [[ -n $subject_path ]]; then subject_path+=","; fi
|
|
|
|
subject_path+='tldr.sha256sums'
|
|
|
|
fi
|
|
|
|
echo "subject_path=$subject_path" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Attest generated files
|
|
|
|
if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main'
|
|
|
|
id: attest
|
|
|
|
uses: actions/attest-build-provenance@v1
|
|
|
|
continue-on-error: true # prevent failing when no pages are modified
|
|
|
|
with:
|
|
|
|
subject-path: ${{ env.subject_path }}
|