|
| 1 | +name: Publish Book and Article as a GH Release |
| 2 | + |
| 3 | +# here's the content of a published theme zip |
| 4 | +# build/ |
| 5 | +# public/ |
| 6 | +# template.yml |
| 7 | +# package-lock.json package.json |
| 8 | +# server.js |
| 9 | +# README.md (copied from the GH repo - hopefully not needed) |
| 10 | + |
| 11 | +# -- as per Makefile they come from |
| 12 | +# build: themes/$(THEME)/build/ (built) |
| 13 | +# public: themes/$(THEME)/public/ (built) |
| 14 | +# template.yml: themes/$(THEME)/ (built) |
| 15 | +# package.json: template/ (sed template->$(THEME) and VERSION->$(VERSION) |
| 16 | +# server.js: template/ (as-is from repo) |
| 17 | + |
| 18 | +on: |
| 19 | + push: |
| 20 | + branches: [ main ] |
| 21 | + tags: [ '*' ] |
| 22 | + |
| 23 | +jobs: |
| 24 | + github-release: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repo |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up Node |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: 24 |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: npm install |
| 38 | + - name: Build |
| 39 | + run: npm run build |
| 40 | + - name: Run tests |
| 41 | + run: npm run test |
| 42 | + |
| 43 | + - name: build book |
| 44 | + run: cd themes/book && npm run prod:build |
| 45 | + # - name: build article |
| 46 | + # run: cd themes/article && npm run prod:build |
| 47 | + |
| 48 | + - name: package book |
| 49 | + run: | |
| 50 | + rm -rf dist-book && mkdir dist-book |
| 51 | + cp -r themes/book/public dist-book/public |
| 52 | + cp -r themes/book/build dist-book/build |
| 53 | + cp -r themes/book/template.yml dist-book/template.yml |
| 54 | + cp template/server.js dist-book/server.js |
| 55 | + VERSION=$(node -p "require('./packages/site/package.json').version") && sed -e "s/VERSION/$VERSION/g" -e "s/THEME/book/g" template/package.json > dist-book/package.json |
| 56 | + cd dist-book && npm install |
| 57 | +
|
| 58 | + # xxx publishing to npm kept out of this workflow for now |
| 59 | + |
| 60 | + # Create zips |
| 61 | + - name: zip artifacts |
| 62 | + run: | |
| 63 | + mkdir dist_zip |
| 64 | + zip -r dist_zip/book-${GITHUB_SHA}.zip dist-book/ |
| 65 | + # zip -r dist_zip/article-${GITHUB_SHA}.zip dist-article/ |
| 66 | + |
| 67 | + # Determine version/tag for naming |
| 68 | + - name: Determine release name |
| 69 | + id: vars |
| 70 | + run: | |
| 71 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 72 | + TAG="${GITHUB_REF#refs/tags/}" |
| 73 | + echo "name=${TAG}" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + echo "name=${GITHUB_SHA}" >> $GITHUB_OUTPUT |
| 76 | + fi |
| 77 | +
|
| 78 | + # Rename final files to use tag if applicable |
| 79 | + - name: Rename zips |
| 80 | + run: | |
| 81 | + if [[ "${{ steps.vars.outputs.name }}" != "${GITHUB_SHA}" ]]; then |
| 82 | + mv dist_zip/book-${GITHUB_SHA}.zip dist_zip/book-${{ steps.vars.outputs.name }}.zip |
| 83 | + mv dist_zip/article-${GITHUB_SHA}.zip dist_zip/article-${{ steps.vars.outputs.name }}.zip |
| 84 | + fi |
| 85 | +
|
| 86 | + # Publish both zips as release assets |
| 87 | + - name: Upload release assets |
| 88 | + uses: softprops/action-gh-release@v2 |
| 89 | + with: |
| 90 | + name: "Build ${{ steps.vars.outputs.name }}" |
| 91 | + tag_name: "${{ steps.vars.outputs.name }}" |
| 92 | + files: | |
| 93 | + dist_zip/book-${{ steps.vars.outputs.name }}.zip |
| 94 | + dist_zip/article-${{ steps.vars.outputs.name }}.zip |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments