Skip to content

Open Source Premium Checks (#16) #47

Open Source Premium Checks (#16)

Open Source Premium Checks (#16) #47

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
release:
types: [published]
jobs:
tlint:
name: Lint checks
runs-on: ubuntu-20.04
container:
image: ghcr.io/trento-project/tlint:latest
volumes:
- ${{ github.workspace }}:/data
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run TLint
run: "/home/tlint/tlint lint -f /data/checks"
obs-commit-rpm:
name: Commit to OBS to generate a RPM package
needs: [tlint]
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
container:
image: ghcr.io/trento-project/continuous-delivery:main
env:
OBS_USER: ${{ secrets.OBS_USER }}
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT }}
OSC_CHECKOUT_DIR: /tmp/trento-checks-package
REPOSITORY: ${{ github.repository }}
FOLDER: packaging/suse/rpm
options: -u 0:0
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure OSC
run: |
mkdir -p $HOME/.config/osc
cp /home/osc/.config/osc/oscrc $HOME/.config/osc
/scripts/init_osc_creds.sh
- name: Prepare _service file
run: |
git config --global --add safe.directory /__w/checks/checks
VERSION=$(./hack/get_version_from_git.sh)
sed -i 's~%%REVISION%%~${{ github.sha }}~' $FOLDER/_service && \
sed -i 's~%%REPOSITORY%%~'"${REPOSITORY}"'~' $FOLDER/_service && \
sed -i 's~%%VERSION%%~'"${VERSION}"'~' $FOLDER/_service
- name: Checkout and prepare OBS package
run: |
osc checkout $OBS_PROJECT trento-checks -o $OSC_CHECKOUT_DIR
cp $FOLDER/_service $OSC_CHECKOUT_DIR
cp $FOLDER/trento-checks.spec $OSC_CHECKOUT_DIR
rm -vf $OSC_CHECKOUT_DIR/*.tar.gz
pushd $OSC_CHECKOUT_DIR
osc service manualrun
rm -vf $OSC_CHECKOUT_DIR/*.tgz
- name: Prepare trento-checks.changes file
# The .changes file is updated only in release creation. This current task should be improved
# in order to add the current rolling release notes
if: github.event_name == 'release'
run: |
git config --global --add safe.directory /__w/checks/checks
VERSION=$(./hack/get_version_from_git.sh)
TAG=$(echo $VERSION | cut -f1 -d+)
hack/gh_release_to_obs_changeset.py $REPOSITORY -a [email protected] -t $TAG -f $OSC_CHECKOUT_DIR/trento-checks.changes
- name: Commit changes into OBS
run: |
pushd $OSC_CHECKOUT_DIR
osc ar
osc commit -m "GitHub Actions automated update to reference ${{ github.sha }}"
obs-commit-image:
name: Commit to OBS to generate a container image
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
needs: [tlint]
container:
image: ghcr.io/trento-project/continuous-delivery:main
env:
FOLDER: packaging/suse/container
NAME: trento-checks-image
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT }}
OBS_USER: ${{ secrets.OBS_USER }}
OSC_CHECKOUT_DIR: /tmp/trento-checks-image
REPOSITORY: ${{ github.repository }}
options: -u 0:0
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-ecosystem/action-get-latest-tag@v1
id: latest-tag
with:
semver_only: true
initial_version: 0.0.1
- name: Configure OSC
run: |
mkdir -p $HOME/.config/osc
cp /home/osc/.config/osc/oscrc $HOME/.config/osc
/scripts/init_osc_creds.sh
- name: Prepare .changes file
# The .changes file is updated only in release creation. This current task should be improved
# in order to add the current rolling release notes
if: github.event_name == 'release'
run: |
CHANGES_FILE=$NAME.changes
osc checkout $OBS_PROJECT $NAME $CHANGES_FILE
mv $CHANGES_FILE $FOLDER
VERSION=${{ steps.latest-tag.outputs.tag }}
hack/gh_release_to_obs_changeset.py $REPOSITORY -a [email protected] -t $VERSION -f $FOLDER/$CHANGES_FILE
- name: Set version
run: |
git config --global --add safe.directory /__w/checks/checks
VERSION=$(./hack/get_version_from_git.sh)
# "+" character is not allowed in OBS dockerfile version strings
VERSION=${VERSION//[+]/-}
sed -i 's~%%VERSION%%~'"${VERSION}"'~' $FOLDER/Dockerfile
- name: Commit on OBS
run: |
OBS_PACKAGE=$OBS_PROJECT/$NAME
osc checkout $OBS_PACKAGE -o $OSC_CHECKOUT_DIR
cp -r $FOLDER/* $OSC_CHECKOUT_DIR
tar --transform 's,^./,/checks/,' -zcvf $OSC_CHECKOUT_DIR/checks.tar.gz --exclude=./.git ./*
cd $OSC_CHECKOUT_DIR
osc ar
osc commit -m "New development version of $NAME released"
github-release-container:
name: Release container to GitHub container registry
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
needs: [tlint]
env:
IMAGE_TAG: "${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'push' && github.ref == 'refs/heads/main' && 'rolling') || github.sha }}"
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create checks tarball
run: |
mkdir checks.dist
cp -r bin checks.dist
cp -r checks checks.dist
mv checks checks.orig
mv checks.dist checks
tar -czf checks.tar.gz checks
mv checks.orig checks
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: packaging/suse/container/Dockerfile
push: true # Will only build if this is not here
tags: |
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}