Files
java-devops-demo/gitea-actions/.gitea/workflows/ci.yaml
T

75 lines
2.7 KiB
YAML

# Gitea Actions pipeline for the gitea-actions-demo service.
#
# IMPORTANT: Gitea only looks for workflows in <repository root>/.gitea/workflows/.
# This file sits inside a module of a shared repository, so Gitea will NOT run it here.
# Copy it to the root of your own project (and drop the working-directory lines).
# It was NOT executed by a Gitea runner while writing the post; every command in it was
# executed by scripts/*.sh instead. See the post for what that does and does not prove.
name: ci
on:
push:
branches: [main]
tags: ['v*']
pull_request:
concurrency:
group: ci-${{ gitea.ref }}
cancel-in-progress: true
defaults:
run:
working-directory: gitea-actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '25'
cache: maven # caches ~/.m2/repository, keyed on pom.xml
# Unit tests (surefire), jar, SBOM, then integration tests (failsafe + Testcontainers).
- name: Build, test, SBOM
run: mvn -B -ntp verify
# GITEA_TOKEN cannot publish packages, so a personal access token with
# write:package lives in a repository secret named PACKAGES_TOKEN.
- name: Publish SBOM to the generic package registry
if: gitea.event_name == 'push'
env:
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
run: |
VERSION="$(mvn -q -ntp help:evaluate -Dexpression=project.version -DforceStdout)"
curl --fail --user "${{ gitea.repository_owner }}:${PACKAGES_TOKEN}" \
--upload-file target/classes/META-INF/sbom/application.cdx.json \
"${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/gitea-actions-demo-sbom/${VERSION}-${{ gitea.run_number }}/application.cdx.json"
image:
needs: build
if: gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '25'
cache: maven
# Jib builds and pushes the image straight to the registry: no Docker daemon needed.
# vars.IMAGE_NAME is e.g. registry.example.com/owner/gitea-actions-demo
- name: Build and push image with Jib
env:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: >
mvn -B -ntp -DskipTests jib:build
-Dimage.name=${{ vars.IMAGE_NAME }}
-Djib.to.auth.username="$REGISTRY_USER"
-Djib.to.auth.password="$REGISTRY_PASSWORD"