GitHub Actions: Difference between revisions

From Torben's Wiki
 
Line 141: Line 141:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     container: ubuntu:24.04
     container: ubuntu:24.04
for python you need to install it manually, but better use ubuntu-latest without container but with actions/setup-python@v5 and python-version: "3.12"
name: Check and Test Python Project via Docker
on:
  workflow_dispatch:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
permissions:
  contents: read
jobs:
  check:
    runs-on: ubuntu-latest
    container: ubuntu:24.04
    steps:
      - name: checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
          fetch-depth: 1 # 0 if you want to push to repo
      # - name: python set up
      #  uses: actions/setup-python@v5
      #  with:
      #    python-version: "3.12"
      #    cache: "pip"
      # - name: python cache set up
      #  uses: actions/cache@v4
      #  with:
      #    path: ${{ env.pythonLocation }}
      #    key: ${{ env.pythonLocation }}-py-cache
      - name: install python and git
        run: |
          apt-get update -y > /dev/null
          apt-get install -y lsb-release python3 python3-pip python3.12-venv python-is-python3 git > /dev/null
          git init
      - name: install dependencies via pip
        run: |
          python -m venv .venv
          . .venv/bin/activate
          if [ -f requirements.txt ]; then pip --no-cache-dir install -r requirements.txt; fi
          pip --no-cache-dir install pre-commit
      - name: run pytest
        run: |
          . .venv/bin/activate
          pip install pytest
          cp src/rememberthemilk.ini.example src/rememberthemilk.ini
          pytest

Latest revision as of 11:12, 29 April 2024

Manual, see [1]


Workflows

Check new Commits and PRs

(copy from edit mode since the display here is wrong)

# This workflow performs chapter quality (known issues) and code quality checks upon new commits and PRs.
# Configured in .pre-commit-config.yaml and setup.cfg

name: Check new commits and PRs

on:
  workflow_dispatch:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

permissions:
  contents: read

jobs:
  check:

    runs-on: ubuntu-22.04

    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.10"

    - name: Set up Python cache
      uses: actions/cache@v3
      with:
        path: $Template:Env.pythonLocation
        key: $Template:Env.pythonLocation-py-cache

    - name: Check of chapters for known issues
      run: python3 -O scripts/check-chapters.py

    - name: Check pre-commit tests
      uses: pre-commit/action@v3.0.0

Make Release, manual input

(copy from edit mode since the display here is wrong)

# This manually started workflow builds and creates a new release including the assets.

name: "Create Release" 

on:
  workflow_dispatch:
    inputs:
      version_number:
        description: 'Version number'
        required: true
        default: 'v1.2.1'
      version_text:
        description: 'Description'
        required: false
        default: 

jobs:
  release:
    runs-on: ubuntu-22.04

    steps:
    - name: Test print input
      run: |
        # env var
        echo "version_number: $Template:Github.event.inputs.version number"
        echo "version_number: $Template:Github.event.inputs.version text"

    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Python set up
      uses: actions/setup-python@v4
      with:
        python-version: '3.10'

    - name: Python cache set up
      uses: actions/cache@v3
      with:
        path: $Template:Env.pythonLocation
        key: $Template:Env.pythonLocation-py-cache

    - name: Run pre-commit tests
      # configured in .pre-commit-config.yaml and setup.cfg
      uses: pre-commit/action@v3.0.0

    - name: Install requirements
      run: sh scripts/install_requirements.sh > /dev/null

    - name: Make
      run: my_make.sh
 
    - name: Create release
      uses: softprops/action-gh-release@v1
      with:
        # action var
        tag_name: "$Template:Inputs.version number"
        prerelease: false
        files: |
          ./hpmor*.pdf
          ./hpmor.epub

Tricks

Caching Python pip packages

    - name: Python set up
      uses: actions/setup-python@v4
      with:
        python-version: '3.10'

    - name: Python cache set up
      uses: actions/cache@v3
      with:
        path: $Template:Env.pythonLocation
        key: $Template:Env.pythonLocation-py-cache

Caching apt packages

    - name: Install packages using cache
      uses: awalsh128/cache-apt-pkgs-action@latest
      with:
        packages: texlive-extra-utils pandoc calibre imagemagick ghostscript
        version: 1.0
        # execute_install_scripts: true

Setup Linux environment to DE language

   - name: Setup environment to DE lang
     run: |
       cd /usr/share/locales
       sudo ./install-language-pack de_DE.UTF-8

Using Docker Container

jobs:
  check:
    runs-on: ubuntu-latest
    container: ubuntu:24.04

for python you need to install it manually, but better use ubuntu-latest without container but with actions/setup-python@v5 and python-version: "3.12"

name: Check and Test Python Project via Docker

on:
  workflow_dispatch:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    container: ubuntu:24.04

    steps:
      - name: checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
          fetch-depth: 1 # 0 if you want to push to repo

      # - name: python set up
      #   uses: actions/setup-python@v5
      #   with:
      #     python-version: "3.12"
      #     cache: "pip"

      # - name: python cache set up
      #   uses: actions/cache@v4
      #   with:
      #     path: $Template:Env.pythonLocation
      #     key: $Template:Env.pythonLocation-py-cache

      - name: install python and git
        run: |
          apt-get update -y > /dev/null
          apt-get install -y lsb-release python3 python3-pip python3.12-venv python-is-python3 git > /dev/null
          git init

      - name: install dependencies via pip
        run: |
          python -m venv .venv
          . .venv/bin/activate
          if [ -f requirements.txt ]; then pip --no-cache-dir install -r requirements.txt; fi
          pip --no-cache-dir install pre-commit

      - name: run pytest
        run: |
          . .venv/bin/activate
          pip install pytest
          cp src/rememberthemilk.ini.example src/rememberthemilk.ini
          pytest