CI by Jo5ta #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI Pipeline | |
| run-name: CI by ${{ github.actor }} | |
| on: | |
| push: | |
| branches: ['main'] | |
| pull_request: | |
| branches: ['main'] | |
| env: | |
| CI: true | |
| CONTAINER_TARGET: ci | |
| CONTAINER_CMD: docker | |
| CONTAINER_NON_INTERACTIVE: true | |
| # Required for pushing to ghcr.io and creating releases | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| # ============================================ | |
| # Quick checks (format, version) - fail fast | |
| # ============================================ | |
| checks: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Load CI-Container | |
| uses: ./.github/actions/load-container | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Format Check | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_format.sh | |
| - name: Fetch main branch for version check | |
| if: github.event_name == 'pull_request' | |
| run: git fetch origin main:main | |
| - name: Version Check | |
| if: github.event_name == 'pull_request' | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_version.sh | |
| # ============================================ | |
| # Build and Test | |
| # ============================================ | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| needs: checks | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup ccache | |
| run: mkdir -p ~/.ccache | |
| - name: Restore ccache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.ccache | |
| key: ccache-${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-${{ github.sha }} | |
| restore-keys: | | |
| ccache-${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}- | |
| ccache-${{ runner.os }}-build- | |
| - name: Load CI-Container | |
| uses: ./.github/actions/load-container | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_build.sh | |
| - name: Show ccache stats | |
| run: ./scripts/container.sh ccache --show-stats || true | |
| - name: Test | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_test.sh | |
| - name: Memory Check | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_memcheck.sh | |
| # ============================================ | |
| # Packaging | |
| # ============================================ | |
| package: | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup ccache | |
| run: mkdir -p ~/.ccache | |
| - name: Restore ccache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.ccache | |
| key: ccache-${{ runner.os }}-package-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-${{ github.sha }} | |
| restore-keys: | | |
| ccache-${{ runner.os }}-package-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}- | |
| ccache-${{ runner.os }}-package- | |
| ccache-${{ runner.os }}-build- | |
| - name: Load CI-Container | |
| uses: ./.github/actions/load-container | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Package | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_package.sh | |
| - name: Show ccache stats | |
| run: ./scripts/container.sh ccache --show-stats || true | |
| - name: Package Validate | |
| run: ./scripts/container.sh ./scripts/ci-cd/step_package_validate.sh --skip-srpm-rebuild | |
| # ========================================== | |
| # Create GitHub Release (only on push to main) | |
| # ========================================== | |
| - name: Get version and generate release info | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| id: release_info | |
| env: | |
| COMMIT_SHA: ${{ github.sha }} | |
| run: | | |
| VERSION=$(head -n1 VERSION.md) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Create a unique tag using version + short commit hash | |
| SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7) | |
| echo "tag=v${VERSION}+${SHORT_SHA}" >> $GITHUB_OUTPUT | |
| # Generate checksums | |
| cd build/packages | |
| sha256sum *.src.rpm > SHA256SUMS | |
| # Build release body with checksums embedded | |
| cd ../.. | |
| cat > release_body.md << EOF | |
| Release of Common Low Level Tracing Kit | |
| **Commit:** ${COMMIT_SHA} | |
| ## Install from SRPM | |
| \`\`\`bash | |
| rpmbuild --rebuild clltk-${VERSION}-*.src.rpm | |
| sudo dnf install ~/rpmbuild/RPMS/x86_64/clltk-*.rpm | |
| \`\`\` | |
| ## Checksums (SHA256) | |
| \`\`\` | |
| $(cat build/packages/SHA256SUMS) | |
| \`\`\` | |
| EOF | |
| - name: Create Release | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release_info.outputs.tag }} | |
| name: ${{ steps.release_info.outputs.version }} | |
| body_path: release_body.md | |
| files: | | |
| build/packages/*.src.rpm | |
| build/packages/SHA256SUMS |