Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# SPDX-License-Identifier: Apache-2.0
# yamllint disable rule:line-length

name: Test

on:
workflow_dispatch:
push:
branches:
- "main"
- "release-**"
paths:
- '**.py'
- 'requirements**.txt'
- 'tox.ini'
- 'actions/**.sh'
- '.github/workflows/test.yml' # This workflow
pull_request:
branches:
- "main"
- "release-**"
paths:
- '**.py'
- 'requirements**.txt'
- 'tox.ini'
- 'actions/**.sh'
- '.github/workflows/test.yml' # This workflow

env:
LC_ALL: en_US.UTF-8

defaults:
run:
shell: bash

permissions:
contents: read

jobs:
test-workflow-ready:
permissions:
checks: read
uses: ./.github/workflows/status-checks.yml
with:
# The unit and functional tests will not start until the following job IDs have succeeded
job_ids: >- # Space-separated job ids to wait on for status checks
DCO
shellcheck
lint-workflow-complete

test:
# Start name with 'test:' for test-workflow-complete job_ids
name: "test: ${{ matrix.python }} on ${{ matrix.platform }}"
needs: ["test-workflow-ready"]
runs-on: "${{ matrix.platform }}"
strategy:
fail-fast: false
matrix:
python:
- "3.10"
- "3.11"
platform:
- "ubuntu-latest"
include:
- python: "3.11"
platform: "macos-latest"
steps:
- name: "Harden Runner"
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# https://github.com/actions/checkout/issues/249
fetch-depth: 0

# Always apt-get update before installing any extra packages
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/customizing-github-hosted-runners#installing-software-on-ubuntu-runners
- name: Update apt index
if: startsWith(matrix.platform, 'ubuntu')
run: |
sudo apt-get update

- name: Install tools on MacOS
if: startsWith(matrix.platform, 'macos')
run: |
brew install expect coreutils bash skopeo

- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: ${{ matrix.python }}
## TODO: Uncomment once this change merges into `main`. We can't use caching until it's merged.
# cache: pip
# cache-dependency-path: |
# **/requirements*.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh>=1.2

- name: Run Bash "unit" tests with tox on MacOS
if: startsWith(matrix.platform, 'macos')
run: |
tox -e launch-ec2-runner-with-fallback

# Default shell on Ubuntu is 'dash', so we need to override the default shell
- name: Run Bash "unit" tests with tox on Linux
if: startsWith(matrix.platform, 'ubuntu')
run: |
# Forcefully overwrite the symlink from `/bin/sh -> /bin/dash` to: `/bin/sh -> /bin/bash`.
sudo ln -sf /bin/bash /bin/sh
tox -e launch-ec2-runner-with-fallback
shell: bash

test-workflow-complete:
permissions:
checks: read
uses: ./.github/workflows/status-checks.yml
with:
job_ids: >- # Space-separated job ids to wait on for status checks
test-workflow-ready
test:
5 changes: 4 additions & 1 deletion .yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ rules:
line-length:
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: false
allow-non-breakable-inline-mappings: false
ignore:
# REASON: This file needs lines that are longer than 120 in order to load variables to the env
- /actions/launch-ec2-runner-with-fallback/action.yml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Below is a list of the in-house GitHub actions stored in this repository:
| Name | Description | Example Use Cases |
| --- | --- | --- |
| [free-disk-space](./actions/free-disk-space/free-disk-space.md) | Used to reclaim disk space on either a GitHub or EC2 runner. | <ul><li>If a CI job tends to fail due to "insufficient disk space"</li><li>If you want to reduce cloud costs by reclaiming disk space instead of increasing your writeable cloud storage to compensate for a bloated EC2 image</li></ul> |
| [launch-ec2-runner-with-fallback](./actions/launch-ec2-runner-with-fallback/launch-ec2-runner-with-fallback.md) | Used launch an EC2 instance in AWS, either as a spot instance or a dedicated instance. If your preferred availability zone lacks availability for your instance type, "backup" availability zones will be tried. | <ul><li>Insufficient capacity in AWS (i.e., AWS lacks availablility for your desired EC2 instance type in your preferred availability zone)</li><li>Cost savings (i.e., You want to try launching your EC2 runner as a spot instance first)</li></ul> |

## How to Use One or More In-House GitHub Actions

Expand Down
3 changes: 3 additions & 0 deletions actions/free-disk-space/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

name: 'Free Disk Space'
description: 'Frees disk space on the runner'
author: 'InstructLab'
runs:
using: "composite"
steps:
Expand Down
Loading
Loading