diff --git a/.github/workflows/printcss.yml b/.github/workflows/printcss.yml index 6ecd0b10..3a2885f0 100644 --- a/.github/workflows/printcss.yml +++ b/.github/workflows/printcss.yml @@ -2,6 +2,22 @@ name: PrintCSS on: workflow_dispatch: + inputs: + tag_name: + description: "Tag name for release (empty for no release)" + required: false + default: contiguous + push: + branches: [ "main" ] + tags: ["v[0-9]+.[0-9]+.[0-9]+*"] + paths: + - README.md + - src/现代C++题目/** + pull_request: + branches: [ "main" ] + paths: + - README.md + - src/现代C++题目/** jobs: prepare: @@ -119,3 +135,60 @@ jobs: path: | homework_problemtext.pdf homework_full.pdf + + release: + runs-on: ubuntu-latest + needs: build-printcss + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: pdf + path: artifacts + + - name: Archive and compress + run: | + find artifacts/ -printf "%P\n" | tar -cvf adocs.tar --no-recursion -C artifacts/ -T - + zstd -z -1 adocs.tar -o loser-homework-pdf.tar.zst + + - if: github.event_name == 'workflow_dispatch' + run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV + + - if: github.event_name == 'schedule' + run: echo 'TAG_NAME=contiguous' >> $GITHUB_ENV + + - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + run: | + TAG_NAME=${{ github.ref }} + echo "TAG_NAME=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV + echo "DRAFT=true" >> $GITHUB_ENV + + - if: env.TAG_NAME == 'contiguous' + name: Delete previous contiguous + env: + GH_TOKEN: ${{ github.token }} + run: | + echo 'PRERELEASE=true' >> $GITHUB_ENV + gh release delete contiguous --yes || true + git config user.name github-actions + git config user.email github-actions@github.com + git push origin :contiguous || true + - name: Rename release files + run: | + mv loser-homework-pdf.tar.zst loser-homework-pdf-${{ env.TAG_NAME }}.tar.zst + - name: Wait a sec + run: sleep 2 + - name: Release + uses: softprops/action-gh-release@v1 + if: github.event_name != 'pull_request' && env.TAG_NAME != '' + with: + name: "Docs ${{ env.TAG_NAME }}" + prerelease: ${{ env.PRERELEASE != '' }} + files: loser-homework-docs-nightly.tar.zst + tag_name: ${{ env.TAG_NAME }} + draft: ${{ env.DRAFT != '' || null }} +