Sunday, November 30, 2025

What are some of the additional workflow commands that can be added to GitHub action

Additional Components You Can Add:

1. More Trigger Events

yaml

on:

  push:

    branches: [main, develop]

  pull_request:

    branches: [main]

  schedule:

    - cron: '0 2 * * *'  # Daily at 2 AM

  workflow_dispatch:  # Manual trigger

2. Environment and Strategy

yaml

jobs:

  test:

    runs-on: ${{ matrix.os }}

    strategy:

      matrix:

        os: [ubuntu-latest, windows-latest]

        python-version: [3.8, 3.9, '3.10']

3. Services (like databases)

yaml

services:

  postgres:

    image: postgres:13

    env:

      POSTGRES_PASSWORD: postgres

4. Conditional Execution

yaml

steps:

  - name: Deploy

    if: github.ref == 'refs/heads/main'

    run: echo "Deploying..."

5. Artifacts and Caching

yaml

steps:

  - uses: actions/cache@v3

    with:

      path: ~/.cache/pip

      key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}

  

  - uses: actions/upload-artifact@v3

    with:

      name: model-files

      path: models/

6. Matrix Builds

yaml

strategy:

  matrix:

    node-version: [14.x, 16.x, 18.x]

    include:

      - node-version: 18.x

        flags: --experimental-feature

7. Job Outputs and Needs

yaml

jobs:

  job1:

    outputs:

      version: ${{ steps.get_version.outputs.version }}

    steps:

      - id: get_version

        run: echo "::set-output name=version::1.0.0"

  

  job2:

    needs: job1

    steps:

      - run: echo "Version is ${{ needs.job1.outputs.version }}"

8. Different Runner Types

yaml

runs-on: 

  - ubuntu-latest

  - windows-latest

  - macos-latest

  - self-hosted  # Your own runners

9. Timeout and Concurrency

yaml

timeout-minutes: 30

concurrency:

  group: ${{ github.ref }}

  cancel-in-progress: true

10. More Step Options

yaml

steps:

  - name: Setup Python

    uses: actions/setup-python@v4

    with:

      python-version: '3.9'

  

  - name: Multi-line script

    run: |

      echo "First command"

      echo "Second command"

  

  - name: Continue on error

    continue-on-error: true

    run: risky-command.sh

  

  - name: Working directory

    working-directory: ./src

    run: pwd  # Runs in ./src directory

Your workflow is well-structured with proper job dependencies and environment variable management. The main improvement I'd suggest is fixing the typo in model-traning → model-training for consistency.

No comments:

Post a Comment