Skip to content

Merge pull request #76 from stfc/add_dev_command_launch #128

Merge pull request #76 from stfc/add_dev_command_launch

Merge pull request #76 from stfc/add_dev_command_launch #128

name: Cloud Chatops
on:
push:
branches:
- master
pull_request:
paths:
- ".github/workflows/cloud_chatops.yaml"
- "cloud-chatops/**"
jobs:
test_and_lint:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-20.04','ubuntu-22.04']
python-version: [ "3.12", "3.x" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: |
cd cloud-chatops
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analyse with pylint
run: |
cd cloud-chatops
pylint . --recursive=true --rcfile=.pylintrc
- name: Run tests
run: |
cd cloud-chatops
python3 -m pytest tests
- name: Run tests and collect coverage
run: |
cd cloud-chatops
python3 -m pytest tests --cov-report xml:coverage.xml --cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{secrets.CODECOV_TOKEN}}
files: cloud-chatops/coverage.xml
push_dev_image_harbor:
runs-on: ubuntu-latest
needs: test_and_lint
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor
uses: docker/login-action@v3
with:
registry: harbor.stfc.ac.uk
username: ${{ secrets.STAGING_HARBOR_USERNAME }}
password: ${{ secrets.STAGING_HARBOR_TOKEN }}
- name: Set commit SHA for later
id: commit_sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push to staging project
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
context: "{{defaultContext}}:cloud-chatops"
tags: "harbor.stfc.ac.uk/stfc-cloud-staging/cloud-chatops:${{ steps.commit_sha.outputs.sha_short }}"
check_version_update:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v4
with:
ref: 'master'
path: 'main'
- name: Checkout current working branch
uses: actions/checkout@v4
with:
path: 'branch'
- name: Compare versions
if: ${{ github.ref != 'refs/heads/master' }}
uses: stfc/check-version-action@main
with:
app_version_path: "cloud-chatops/version.txt"
docker_compose_path: "cloud-chatops/docker-compose.yaml"
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
- name: Log App Success
if: ${{ env.app_updated == 'true' }}
run: |
echo "App version has been updated correctly!"
- name: Log Compose Success
if: ${{ env.compose_updated == 'true' }}
run: |
echo "Compose version has been updated correctly!"
push_prod_image_harbor:
runs-on: ubuntu-latest
needs: [test_and_lint, check_version_update]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor
uses: docker/login-action@v3
with:
registry: harbor.stfc.ac.uk
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}
- name: Get release tag for later
id: release_tag
run: echo "version=$(cat cloud-chatops/version.txt)" >> $GITHUB_OUTPUT
- name: Check if release file has updated
uses: dorny/paths-filter@v3
id: release_updated
with:
filters: |
version:
- 'cloud-chatops/version.txt'
- name: Build and push on version change
uses: docker/build-push-action@v6
if: steps.release_updated.outputs.version == 'true'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
context: "{{defaultContext}}:cloud-chatops"
tags: "harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:${{ steps.release_tag.outputs.version }}"