seb-server/.github/workflows/buildReporting.yml

152 lines
4.4 KiB
YAML
Raw Permalink Normal View History

2022-05-03 09:42:17 +02:00
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: build
on:
push:
branches:
- '**'
tags:
- '**'
pull_request:
branches: [master, development]
jobs:
maven-build-reporting:
runs-on: ubuntu-latest
steps:
- name: Get short SHA
2024-03-06 13:01:36 +01:00
uses: benjlevesque/short-sha@v3.0
id: short-sha
- name: Store short SHA as environment variable
run: echo $SHA
env:
SHA: ${{ steps.short-sha.outputs.sha }}
- name: Set env
run: echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Test tag name
run: |
echo $TAG_NAME
echo ${{ env.TAG_NAME }}
2022-05-03 09:42:17 +02:00
-
name: Checkout repository
2024-02-28 16:23:56 +01:00
uses: actions/checkout@v4
2022-05-03 09:42:17 +02:00
-
2024-04-03 16:09:08 +02:00
name: Build Test Reporting
2024-02-28 16:23:56 +01:00
uses: actions/setup-java@v4
2022-05-03 09:42:17 +02:00
with:
2024-03-05 09:59:32 +01:00
java-version: '17'
2022-05-03 09:42:17 +02:00
distribution: 'adopt'
-
name: Cache Maven packages
2024-02-28 16:23:56 +01:00
uses: actions/cache@v4
2022-05-03 09:42:17 +02:00
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
-
name: Build with Maven
run: mvn clean install -e -P let_reporting -Dsebserver-version="${{ env.TAG_NAME }}-${{ env.SHA }}"
env:
sebserver-version: ${{ env.TAG_NAME }}-${{ env.SHA }}
2022-05-03 09:42:17 +02:00
- name: Simplify package name
2022-05-03 09:42:17 +02:00
run: mv target/seb-server-${{ env.TAG_NAME }}-${{ env.SHA }}.jar target/seb-server.jar
- uses: actions/upload-artifact@v4
2022-05-03 09:42:17 +02:00
with:
name: Package
path: target/seb-server.jar
docker-build:
needs: maven-build-reporting
2022-05-03 09:42:17 +02:00
# Run only on tagging
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
2022-12-07 09:18:33 +01:00
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
2022-12-07 09:26:41 +01:00
2022-05-03 09:42:17 +02:00
steps:
-
name: Set env
run: echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
-
name: Test
run: |
echo $TAG_NAME
echo ${{ env.TAG_NAME }}
-
name: Set up QEMU
2024-03-06 12:55:55 +01:00
uses: docker/setup-qemu-action@v3
2022-05-03 09:42:17 +02:00
-
name: Set up Docker Buildx
2024-03-26 16:59:54 +01:00
uses: docker/setup-buildx-action@v3.2.0
2022-05-03 09:42:17 +02:00
-
name: Login to DockerHub
2023-03-07 14:11:20 +01:00
uses: docker/login-action@v2
2022-05-03 09:42:17 +02:00
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Checkout repository
2024-02-28 16:23:56 +01:00
uses: actions/checkout@v4
2022-12-07 09:18:33 +01:00
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
-
name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
2022-05-03 09:42:17 +02:00
-
name: Download a single artifact
2024-02-28 16:23:56 +01:00
uses: actions/download-artifact@v4
2022-05-03 09:42:17 +02:00
with:
name: Package
2022-12-07 09:55:50 +01:00
-
name: Extract metadata (tags, labels) for Docker
id: meta
2023-03-07 14:11:20 +01:00
uses: docker/metadata-action@v4
2022-12-07 09:55:50 +01:00
with:
images: anhefti/seb-server
tags: |
2022-12-08 09:45:42 +01:00
type=raw,${{ env.TAG_NAME }}
2022-05-03 09:42:17 +02:00
-
name: Build and push
id: docker_build
2023-03-07 14:11:20 +01:00
uses: docker/build-push-action@v4
2022-05-03 09:42:17 +02:00
with:
context: .
file: ./docker/Dockerfile
push: true
tags: |
2022-12-07 09:18:33 +01:00
anhefti/seb-server:${{ env.TAG_NAME }}
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
2023-03-06 14:33:59 +01:00
run: yes | cosign sign ${TAGS}
2022-12-07 09:18:33 +01:00
env:
COSIGN_EXPERIMENTAL: true
2022-12-08 09:18:20 +01:00
TAGS: ${{ steps.meta.outputs.tags }}
cleanup:
2024-03-20 09:01:47 +01:00
needs: [maven-build-reporting, docker-build]
2024-03-20 09:07:57 +01:00
if: |
always()
runs-on: ubuntu-latest
steps:
-
name: Delete Artifacts
2024-03-20 08:57:34 +01:00
uses: geekyeggo/delete-artifact@v5
with:
name: Package