Programming exercises
: Only replace existing files when populating build plan repositories
#45328
Workflow file for this run
This file contains 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: Build | |
on: | |
pull_request: | |
paths-ignore: | |
- 'README.md' | |
- 'CODE_OF_CONDUCT.md' | |
- 'CONTRIBUTING.md' | |
- 'LICENSE' | |
- 'SECURITY.md' | |
- 'docs/**' | |
- '.github/**' | |
- '!.github/workflows/build.yml' | |
- '!.github/workflows/testserver.yml' | |
push: | |
branches: | |
- develop | |
- main | |
- release/* | |
tags: '[0-9]+.[0-9]+.[0-9]+' | |
paths-ignore: | |
- 'README.md' | |
- 'CODE_OF_CONDUCT.md' | |
- 'CONTRIBUTING.md' | |
- 'LICENSE' | |
- 'SECURITY.md' | |
- 'docs/**' | |
- '.github/**' | |
- '!.github/workflows/build.yml' | |
release: | |
types: | |
- created | |
# Keep in sync with codeql-analysis.yml and test.yml and analysis-of-endpoint-connections.yml | |
env: | |
CI: true | |
node: 20 | |
java: 21 | |
RAW_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }} | |
jobs: | |
build: | |
name: Build .war artifact | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '${{ env.node }}' | |
cache: 'npm' | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '${{ env.java }}' | |
cache: 'gradle' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Production Build | |
run: ./gradlew -Pprod -Pwar clean bootWar | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Artemis.war | |
path: build/libs/Artemis-*.war | |
- name: Upload Release Artifact | |
if: github.event_name == 'release' && github.event.action == 'created' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ github.event.release.upload_url }} | |
asset_path: build/libs/Artemis-${{ github.event.release.tag_name }}.war | |
asset_name: Artemis.war | |
asset_content_type: application/x-webarchive | |
docker: | |
name: Build and Push Docker Image | |
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'ls1intum/Artemis' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Compute Tag | |
uses: actions/github-script@v7 | |
id: compute-tag | |
with: | |
result-encoding: string | |
script: | | |
if (context.eventName === "pull_request") { | |
return "pr-" + context.issue.number; | |
} | |
if (context.eventName === "release") { | |
return "latest"; | |
} | |
if (context.eventName === "push") { | |
if (context.ref.startsWith("refs/tags/")) { | |
return context.ref.slice(10); | |
} | |
if (context.ref === "refs/heads/develop") { | |
return "develop"; | |
} | |
} | |
return "FALSE"; | |
- name: Git Checkout for PRs | |
if: ${{ github.event_name == 'pull_request' }} | |
# Checkout pull request HEAD commit instead of merge commit | |
# this is done to include the correct branch and git information inside the build | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Git Checkout for push actions | |
if: ${{ github.event_name == 'push' }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Git Checkout for push actions | |
if: ${{ github.event_name == 'release' }} | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Build and Push to GitHub Container Registry | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
if: ${{ steps.compute-tag.outputs.result != 'FALSE' }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and Push to GitHub Container Registry | |
uses: docker/build-push-action@v5 | |
if: ${{ steps.compute-tag.outputs.result != 'FALSE' }} | |
with: | |
# beware that the linux/arm64 build from the registry is using an amd64 compiled .war file as | |
# the GitHub runners don't support arm64 and QEMU takes too long for emulating the build | |
platforms: linux/amd64,linux/arm64 | |
file: ./docker/artemis/Dockerfile | |
context: . | |
tags: ghcr.io/ls1intum/artemis:${{ steps.compute-tag.outputs.result }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=min | |
# TODO: Push to Docker Hub (develop + tag) | |
# TODO: Push to Chair Harbour (??) |