diff --git a/.github/workflows/generate-e-books.yaml b/.github/workflows/generate-e-books.yaml new file mode 100644 index 00000000..cec0ea98 --- /dev/null +++ b/.github/workflows/generate-e-books.yaml @@ -0,0 +1,63 @@ +name: Generate e-books + +on: + pull_request: + branches: + - master + workflow_dispatch: {} # For manual runs. + +jobs: + build-for-pr: + # For every PR, build the same artifacts and make them accessible from the PR. + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + + - name: Upload PR artifacts + uses: actions/upload-artifact@v4 + with: + name: ebooks-${{ github.sha }} + path: artifacts/* + if-no-files-found: error + # Change the retention period here if necessary. + retention-days: 90 + + - name: Add a comment with a link to the generated artifacts. + # For forked PRs the token is read-only; skip commenting to avoid failures. + if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} + uses: actions/github-script@v7 + env: + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + with: + script: | + const body = [ + `E-books generated for this pull request available at: ${process.env.RUN_URL}` + ].join('\n'); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body + }); diff --git a/.github/workflows/generate_release.yaml b/.github/workflows/generate_release.yaml deleted file mode 100644 index df932c1c..00000000 --- a/.github/workflows/generate_release.yaml +++ /dev/null @@ -1,123 +0,0 @@ -name: Generate e-books - -on: - push: - tags: - - 'v*.*' # Create a release only when a new tag matching v*.* is pushed. - # To also create a release for each push to the main branch, uncomment the following 2 lines: - # branches: - # - master - pull_request: - branches: - - master - workflow_dispatch: {} # For manual runs. - -jobs: - release-ebooks: - # Run for tag pushes (and optionally for branch pushes if the "branches" node is uncommented above). - if: github.event_name != 'pull_request' - runs-on: ubuntu-latest - - permissions: - contents: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Export all supported book formats from the Docker container - run: | - make run - make export - - - name: Copy generated files to host system - run: | - make cp - mkdir -p artifacts/ - mv "Linux Inside - 0xAX.epub" \ - "Linux Inside - 0xAX.mobi" \ - "Linux Inside - 0xAX.pdf" \ - "Linux Inside - 0xAX (A5).pdf" \ - artifacts/ - cp LICENSE artifacts/ - - - name: Prepare release metadata - # Use tag name when running on a tag, otherwise fall back to the short commit hash. - id: meta - env: - GITHUB_REF_TYPE: ${{ github.ref_type }} - GITHUB_REF_NAME: ${{ github.ref_name }} - run: | - DATE_US="$(date -u '+%m/%d/%Y %H:%M')" - if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then - LABEL="${GITHUB_REF_NAME}" - else - LABEL="$(git rev-parse --short HEAD)" - fi - echo "release_name=${DATE_US} (${LABEL})" >> "$GITHUB_OUTPUT" - echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT" - - - name: Create GitHub release - uses: softprops/action-gh-release@v2 - with: - files: artifacts/* - name: ${{ steps.meta.outputs.release_name }} - tag_name: ${{ steps.meta.outputs.tag_name }} - target_commitish: ${{ github.sha }} - generate_release_notes: true - fail_on_unmatched_files: true - - build-for-pr: - # For every PR, build the same artifacts and make them accessible from the PR. - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - - permissions: - contents: read - pull-requests: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Export all supported book formats from the Docker container - run: | - make run - make export - - - name: Copy generated files to host system - run: | - make cp - mkdir -p artifacts/ - mv "Linux Inside - 0xAX.epub" \ - "Linux Inside - 0xAX.mobi" \ - "Linux Inside - 0xAX.pdf" \ - "Linux Inside - 0xAX (A5).pdf" \ - artifacts/ - - - name: Upload PR artifacts - uses: actions/upload-artifact@v4 - with: - name: ebooks-${{ github.sha }} - path: artifacts/* - if-no-files-found: error - # Change the retention period here if necessary. - retention-days: 90 - - - name: Add a comment with a link to the generated artifacts. - # For forked PRs the token is read-only; skip commenting to avoid failures. - if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} - uses: actions/github-script@v7 - env: - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - with: - script: | - const body = [ - `E-books generated for this pull request available at: ${process.env.RUN_URL}` - ].join('\n'); - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body - }); \ No newline at end of file diff --git a/.github/workflows/release-e-books.yaml b/.github/workflows/release-e-books.yaml new file mode 100644 index 00000000..66b4dddf --- /dev/null +++ b/.github/workflows/release-e-books.yaml @@ -0,0 +1,63 @@ +name: Release e-books + +on: + push: + tags: + - 'v*.*' # Create a release only when a new tag matching v*.* is pushed. + # To also create a release for each push to the main branch, uncomment the following 2 lines: + # branches: + # - master + workflow_dispatch: {} # For manual runs. + +jobs: + release-ebooks: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + cp LICENSE artifacts/ + + - name: Prepare release metadata + # Use tag name when running on a tag, otherwise fall back to the short commit hash. + id: meta + env: + GITHUB_REF_TYPE: ${{ github.ref_type }} + GITHUB_REF_NAME: ${{ github.ref_name }} + run: | + DATE_UTC="$(date -u '+%m/%d/%Y %H:%M')" + if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then + LABEL="${GITHUB_REF_NAME}" + else + LABEL="$(git rev-parse --short HEAD)" + fi + echo "release_name=${DATE_UTC} (${LABEL})" >> "$GITHUB_OUTPUT" + echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT" + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + files: artifacts/* + name: ${{ steps.meta.outputs.release_name }} + tag_name: ${{ steps.meta.outputs.tag_name }} + target_commitish: ${{ github.sha }} + generate_release_notes: true + fail_on_unmatched_files: true