QuantEcon / meta

For issues and discussion covering more than one repository
0 stars 0 forks source link

Fully Automatic Releases (for book- repository series) #138

Open mmcky opened 8 months ago

mmcky commented 8 months ago

Current the release of the book websites is a two step process:

  1. Setup a sync- release on the private repo
  2. Setup a publish- release on the public repo

This is not convenient. I have experimented with using gh cli to trigger releases on the public repository automatically but I haven't got the config correct after reading the github docs this morning.

We will need to

Template action for test work.

name: Sync with book-dp1-public
on:
  push:
    tags:
      - 'sync*'
jobs:
  sync:
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Git (required to commit notebooks)
        shell: bash -l {0}
        run: apt-get install -y git
      - name: Sync assets to book-dp1-public
        shell: bash -l {0}
        env:
          QE_SERVICES_PAT: ${{ secrets.QUANTECON_SERVICES_PAT }}
        run: |
          git clone https://quantecon-services:$QE_SERVICES_PAT@github.com/quantecon/book-dp1-public

          cp book/dp.pdf book-dp1-public/pdf/

          cp slides/ch_0/ch_0.pdf book-dp1-public/slides/
          cp slides/ch_1/ch_1.pdf book-dp1-public/slides/
          cp slides/ch_2/ch_2.pdf book-dp1-public/slides/
          cp slides/ch_3/ch_3.pdf book-dp1-public/slides/
          cp slides/ch_4/ch_4.pdf book-dp1-public/slides/
          cp slides/ch_5/ch_5.pdf book-dp1-public/slides/
          cp slides/ch_6/ch_6.pdf book-dp1-public/slides/
          cp slides/ch_7/ch_7.pdf book-dp1-public/slides/
          cp slides/ch_8/ch_8.pdf book-dp1-public/slides/
          cp slides/ch_9/ch_9.pdf book-dp1-public/slides/
          cp slides/ch_10/ch_10.pdf book-dp1-public/slides/

          cp source_code_py/* book-dp1-public/code/py/
          cp source_code_jl/* book-dp1-public/code/jl/

          cd book-dp1-public
          git config user.name "QuantEcon Services"
          git config user.email "admin@quantecon.org"
          git add .
          git commit -m "auto sync from book-dp1"
          git push origin main
  publish:
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
    needs: sync
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Git and GH CLI (required to commit notebooks)
        shell: bash -l {0}
        run: |
          sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
          && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
          && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
          && sudo apt update \
          && sudo apt install gh -y  
          apt-get install -y git
      - name: Sync assets to book-dp1-public
        shell: bash -l {0}
        env:
          QE_SERVICES_PAT: ${{ secrets.QUANTECON_SERVICES_PAT }}
        run: |
          git clone https://quantecon-services:$QE_SERVICES_PAT@github.com/quantecon/book-dp1-public
          cd book-dp1-public
          DATE=$(date +%Y%b%d)
          gh release create publish-$DATE --generate-notes