Skip to content

Travis to Github Action Migration #290

Travis to Github Action Migration

Travis to Github Action Migration #290

Workflow file for this run

name: CI & Release
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
common-setup:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check_release.outputs.should_release }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Export Secrets
run: |
echo "RHSM_PASS=${{ secrets.RHSM_PASS }}" >> $GITHUB_ENV
echo "RHSM_USER=${{ secrets.RHSM_USER }}" >> $GITHUB_ENV
env:
RHSM_PASS: ${{ secrets.RHSM_PASS }}
RHSM_USER: ${{ secrets.RHSM_USER }}
- name: Get commit message
id: get_commit
run: |
message=$(git log -1 --pretty=%B)
echo "message=$message" >> "$GITHUB_OUTPUT"
- name: Check if release should be triggered
id: check_release
run: |
if [[ "${{ steps.get_commit.outputs.message }}" == *"release"* ]]; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "Release will be triggered (found 'release' in commit message)"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "Release will NOT be triggered (no 'release' in commit message)"
fi
build-and-test:
needs: common-setup
runs-on: ubuntu-latest
permissions:
contents: write # needed to push coverage to gh-pages
pull-requests: write # needed to comment on PRs
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24.5"
check-latest: true
cache: true
- name: Install system dependencies (bc + docker)
run: |
sudo apt-get update -qq
sudo apt-get install -y bc docker-ce-cli
- name: Make scripts executable
run: chmod +x scripts/*.sh || true
- name: Prepare environment
run: |
export GO111MODULE=on
go mod tidy
make deps
- name: Check code formatting
run: make fmt
- name: Run unit tests
run: make test
- name: Generate coverage
run: |
make coverage
./scripts/calculateCoverage.sh
touch "Passing" || touch "Failed"
- name: Build driver image
run: |
docker build --build-arg RHSM_USER=${{ secrets.RHSM_USER }} --build-arg RHSM_PASS=${{ secrets.RHSM_PASS }} .
- name: Publish coverage
if: success()
env:
GHE_TOKEN: ${{ secrets.GHE_TOKEN }}
run: |
./scripts/publishCoverage.sh
release:
needs: [common-setup, build-and-test]
if: needs.common-setup.outputs.should_release == 'true'
permissions: write-all
runs-on: ubuntu-latest
strategy:
matrix:
package_dir:
- cos-csi-mounter
env:
IS_LATEST_RELEASE: 'true'
APP_VERSION: 1.0.5
steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Print Go Version
run: go version
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "go"
- name: Run Unit Tests for cos csi mounter
run: sudo make ut-coverage -C ${{ matrix.package_dir }}
- name: Build Debian and RPM packages for cos-csi-mounter systemd service
run: |
cd ${{ matrix.package_dir }}
make packages
- name: Get last commit message
id: check_commit
run: |
message=$(git log -1 --pretty=%B)
message="${message//'%'/'%25'}" # Escape '%'
message="${message//$'\n'/'%0A'}" # Escape newlines
message="${message//$'\r'/'%0D'}" # Escape carriage returns
echo "message=$message" >> "$GITHUB_OUTPUT"
shell: bash
- name: Check Commit Message
run: |
echo "Commit Message: ${{ steps.check_commit.outputs.message }}"
- name: Check Commit Message for Release Trigger
id: check_commit_condition
run: |
echo "Commit Message: ${{ steps.check_commit.outputs.message }}"
if [[ "${{ steps.check_commit.outputs.message }}" == *"release"* ]]; then
echo "Release job triggered"
else
echo "No 'release' keyword found in the commit message. Skipping release job."
exit 0 # Exit early to skip the release job
fi
- name: Latest Version (Tag and Release)
if: success()
id: release
uses: softprops/action-gh-release@v2
with:
files: |
/home/runner/work/ibm-object-csi-driver/ibm-object-csi-driver/cos-csi-mounter/cos-csi-mounter-${{ env.APP_VERSION }}.deb.tar.gz
/home/runner/work/ibm-object-csi-driver/ibm-object-csi-driver/cos-csi-mounter/cos-csi-mounter-${{ env.APP_VERSION }}.deb.tar.gz.sha256
/home/runner/work/ibm-object-csi-driver/ibm-object-csi-driver/cos-csi-mounter/cos-csi-mounter-${{ env.APP_VERSION }}.rpm.tar.gz
/home/runner/work/ibm-object-csi-driver/ibm-object-csi-driver/cos-csi-mounter/cos-csi-mounter-${{ env.APP_VERSION }}.rpm.tar.gz.sha256
tag_name: v1.0.5
name: v1.0.5
body: |
## 🚀 What’s New
- Fix for rclone mount hang issue
prerelease: ${{ env.IS_LATEST_RELEASE != 'true' }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3