-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Development: Add Helios-based deployment workflow for test servers an…
…d reusable build logic (#10109)
- Loading branch information
1 parent
c8c93d2
commit 72ca6ae
Showing
3 changed files
with
445 additions
and
105 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
# Build job inputs | ||
build_war: | ||
description: "Whether to build and upload the .war artifact." | ||
required: false | ||
default: false | ||
type: boolean | ||
build_ref: | ||
description: "Branch name, tag, or commit SHA to use for the build job. If not provided, it falls back to the default behavior of actions/checkout." | ||
required: false | ||
default: '' | ||
type: string | ||
|
||
# Upload Release Artifact job inputs | ||
release_upload: | ||
description: "Whether to upload the release artifact." | ||
required: false | ||
default: false | ||
type: boolean | ||
release_url: | ||
description: "URL to upload the release artifact to." | ||
required: false | ||
default: '' | ||
type: string | ||
release_path: | ||
description: "Path to the release artifact." | ||
required: false | ||
default: '' | ||
type: string | ||
release_name: | ||
description: "Name of the release artifact." | ||
required: false | ||
default: '' | ||
type: string | ||
release_type: | ||
description: "Content type of the release artifact." | ||
required: false | ||
default: '' | ||
type: string | ||
|
||
# Docker job inputs | ||
docker: | ||
description: "Whether to build and push a Docker image." | ||
required: false | ||
default: false | ||
type: boolean | ||
docker_ref: | ||
description: "Branch name, tag, or commit SHA to use for the Docker job. If not provided, it falls back to the default behavior of actions/checkout." | ||
required: false | ||
default: '' | ||
type: string | ||
docker_build_tag: | ||
description: "Tag to use when building Docker image." | ||
required: false | ||
default: '' | ||
type: string | ||
|
||
# Keep in sync with codeql-analysis.yml and test.yml and analysis-of-endpoint-connections.yml | ||
env: | ||
CI: true | ||
node: 22 | ||
java: 21 | ||
|
||
jobs: | ||
validate-inputs: | ||
name: Validate Inputs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Validate Inputs | ||
run: | | ||
# Check release related inputs | ||
if [[ "${{ github.event.inputs.release_upload }}" ]]; then | ||
# List of required release inputs | ||
missing_inputs=() | ||
# Check each required input | ||
[[ -z "${{ inputs.release_url }}" || "${{ inputs.release_url }}" == '' ]] && missing_inputs+=("release_url") | ||
[[ -z "${{ inputs.release_path }}" || "${{ inputs.release_path }}" == '' ]] && missing_inputs+=("release_path") | ||
[[ -z "${{ inputs.release_name }}" || "${{ inputs.release_name }}" == '' ]] && missing_inputs+=("release_name") | ||
[[ -z "${{ inputs.release_type }}" || "${{ inputs.release_type }}" == '' ]] && missing_inputs+=("release_type") | ||
if [[ "${#missing_inputs[@]}" -gt 0 ]]; then | ||
echo "::error::Release upload is set to true, but the following inputs are missing: ${missing_inputs[*]}" | ||
exit 1 | ||
fi | ||
fi | ||
# Check Docker related inputs | ||
if [[ "${{ github.event.inputs.docker }}" ]]; then | ||
# Check whether all Docker inputs are set | ||
if [[ "${{ github.event.inputs.docker_build_tag }}" == '' ]]; then | ||
echo "::error::Docker build is set to true, but Docker build tag is not set." | ||
exit 1 | ||
fi | ||
fi | ||
build: | ||
name: Build .war artifact | ||
if: ${{ inputs.build_war }} | ||
needs: validate-inputs | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Git Checkout | ||
- name: Git Checkout to the specific ref (if build_ref is set) | ||
uses: actions/checkout@v4 | ||
if: ${{ inputs.build_ref != '' }} | ||
with: | ||
ref: ${{ inputs.build_ref }} | ||
- name: Git Checkout (default) | ||
uses: actions/checkout@v4 | ||
if: ${{ inputs.build_ref == '' }} | ||
# Setup Node.js, Java and Gradle | ||
- 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 | ||
# Build | ||
- name: Production Build | ||
run: ./gradlew -Pprod -Pwar clean bootWar | ||
# Upload Artifact | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Artemis.war | ||
path: build/libs/Artemis-*.war | ||
# Upload Artifact (Release) | ||
- name: Upload Release Artifact | ||
if: ${{ inputs.release_upload }} | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ inputs.release_url }} | ||
asset_path: ${{ inputs.release_path }} | ||
asset_name: ${{ inputs.release_name }} | ||
asset_content_type: ${{ inputs.release_type }} | ||
|
||
docker: | ||
name: Build and Push Docker Image | ||
if: ${{ inputs.docker }} | ||
needs: validate-inputs | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Git Checkout | ||
- name: Git Checkout to the specific ref (if docker_ref is set) | ||
uses: actions/checkout@v4 | ||
if: ${{ inputs.docker_ref != '' }} | ||
with: | ||
ref: ${{ inputs.docker_ref }} | ||
- name: Git Checkout (default) | ||
uses: actions/checkout@v4 | ||
if: ${{ inputs.docker_ref == '' }} | ||
- 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 | ||
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 | ||
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:${{ inputs.docker_build_tag }} | ||
push: true | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=min | ||
|
||
# TODO: Push to Docker Hub (develop + tag) | ||
|
||
# TODO: Push to Chair Harbour (??) |
Oops, something went wrong.