Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 118 additions & 19 deletions .github/workflows/build-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on:
branches:
- ionos-dev
- ionos-stable
- 'rc/**'
workflow_dispatch: # Manual trigger to bypass all caches
inputs:
force_rebuild:
Expand All @@ -50,7 +51,19 @@ on:
default: ''

concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/ionos-dev' && github.run_id || github.event.pull_request.number || github.ref }}
group: >-
${{ github.workflow }}-${{
github.event_name == 'pull_request'
&& format('pr-{0}', github.event.pull_request.number)
|| (
(
contains(fromJson('["refs/heads/ionos-dev","refs/heads/ionos-stable"]'), github.ref)
|| startsWith(github.ref, 'refs/heads/rc/')
)
&& github.run_id
|| github.ref
)
}}
cancel-in-progress: true

env:
Expand Down Expand Up @@ -142,9 +155,11 @@ jobs:
echo " ✅ Event type is 'push'"
fi

if [ "${{ github.ref_name }}" != "ionos-dev" ] && [ "${{ github.ref_name }}" != "ionos-stable" ]; then
echo "- ❌ Branch must be 'ionos-dev' or 'ionos-stable' (current: \`${{ github.ref_name }}\`)" >> $GITHUB_STEP_SUMMARY
echo " ❌ Branch is '${{ github.ref_name }}' (must be 'ionos-dev' or 'ionos-stable')"
# Check if branch matches expected patterns: ionos-dev, ionos-stable, or rc/*
VALID_BRANCH_PATTERN='^(ionos-dev|ionos-stable)$|^rc/.*$'
if [[ ! "${{ github.ref_name }}" =~ $VALID_BRANCH_PATTERN ]]; then
echo "- ❌ Branch must be 'ionos-dev', 'ionos-stable', or 'rc/*' (current: \`${{ github.ref_name }}\`)" >> $GITHUB_STEP_SUMMARY
echo " ❌ Branch is '${{ github.ref_name }}' (must be 'ionos-dev', 'ionos-stable', or 'rc/*')"
WILL_TRIGGER=false
else
echo "- ✅ Branch is '\`${{ github.ref_name }}\`'" >> $GITHUB_STEP_SUMMARY
Expand Down Expand Up @@ -676,10 +691,10 @@ jobs:

upload-to-artifactory:
runs-on: self-hosted
# Upload the artifact to the Artifactory repository on PR *OR* on "ionos-dev|ionos-stable" branch push defined in the on:push:branches
# Upload the artifact to the Artifactory repository on PR *OR* on "ionos-dev|ionos-stable|rc/*" branch push defined in the on:push:branches
if: |
always() &&
(github.event_name == 'pull_request' || github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable') &&
(github.event_name == 'pull_request' || github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable' || startsWith(github.ref_name, 'rc/')) &&
needs.prepare-matrix.result == 'success' &&
(needs.build-external-apps.result == 'success' || needs.build-external-apps.result == 'skipped') &&
needs.build-artifact.result == 'success'
Expand Down Expand Up @@ -758,21 +773,37 @@ jobs:
- name: Upload build to artifactory
id: artifactory_upload
run: |
# PR builds are stored in a separate directory as "dev/pr/nextcloud-workspace-pr-<number>.zip"
# Push to "ionos-dev" branch is stored as "dev/nextcloud-workspace-<ncVersion>.zip"
# Artifactory Build Storage Structure:
# | Branch/Event | Stage Prefix | Artifact Path |
# |------------------|----------------|--------------------------------------------------------------------------|
# | Pull Request | dev | dev/pr/nextcloud-workspace-pr-<number>.zip |
# | ionos-dev | dev | dev/ncw-<ncVersion>/<shortSha>/nextcloud-workspace-<ncVersion>.zip |
# | ionos-stable | stable | stable/ncw-<ncVersion>/<shortSha>/nextcloud-workspace-<ncVersion>.zip |
# | rc/* | rc | rc/ncw-<ncVersion>/<shortSha>/nextcloud-workspace-<ncVersion>.zip |

ARTIFACTORY_STAGE_PREFIX="dev"

# set ARTIFACTORY_STAGE_PREFIX=stable on ionos-stable branch
# Set stage prefix based on branch
if [ "${{ github.ref_name }}" == "ionos-stable" ]; then
ARTIFACTORY_STAGE_PREFIX="stable"
# set ARTIFACTORY_STAGE_PREFIX=rc on rc/* branches
elif [[ "${{ github.ref_name }}" =~ ^rc/ ]]; then
ARTIFACTORY_STAGE_PREFIX="rc"
fi

export PATH_TO_DIRECTORY="${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}/${ARTIFACTORY_STAGE_PREFIX}"
PATH_TO_FILE="pr/nextcloud-workspace-pr-${{ github.event.pull_request.number }}.zip"

if [ -z "${{ github.event.pull_request.number }}" ]; then
PATH_TO_FILE="nextcloud-workspace-${{ needs.build-artifact.outputs.NC_VERSION }}.zip"
# For PR: use simple pr/<number> path
# For branches: use ncw-<version>/<sha>/ structure to ensure unique paths
if [ -n "${{ github.event.pull_request.number }}" ]; then
PATH_TO_FILE="pr/nextcloud-workspace-pr-${{ github.event.pull_request.number }}.zip"
else
# Extract short SHA (first 7 characters)
SHORT_SHA="${{ github.sha }}"
SHORT_SHA="${SHORT_SHA:0:7}"
NC_VERSION="${{ needs.build-artifact.outputs.NC_VERSION }}"

PATH_TO_FILE="ncw-${NC_VERSION}/${SHORT_SHA}/nextcloud-workspace-${NC_VERSION}.zip"
fi

export PATH_TO_LATEST_ARTIFACT="${PATH_TO_DIRECTORY}/${PATH_TO_FILE}"
Expand Down Expand Up @@ -907,30 +938,98 @@ jobs:
runs-on: self-hosted

name: Trigger remote workflow
needs: [upload-to-artifactory]
# Trigger remote build on "ionos-dev|ionos-stable" branch *push* defined in the on:push:branches
needs: [build-artifact, upload-to-artifactory]
# Trigger remote build on "ionos-dev|ionos-stable|rc/*" branch *push* defined in the on:push:branches
# Can be disabled via repository variable 'DISABLE_REMOTE_TRIGGER' (set to 'true' to disable)
# Configure at: https://github.com/IONOS-Productivity/ncw-server/settings/variables/actions
if: |
always() &&
github.event_name == 'push' &&
(github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable') &&
(github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable' || startsWith(github.ref_name, 'rc/')) &&
needs.build-artifact.result == 'success' &&
needs.upload-to-artifactory.result == 'success' &&
vars.DISABLE_REMOTE_TRIGGER != 'true'
steps:
- name: Check prerequisites
run: |
echo "Checking if all required variables are set..."
error_count=0

# Check secrets
if [ -z "${{ secrets.GITLAB_TOKEN }}" ]; then
echo "::error::GITLAB_TOKEN secret is not set"
error_count=$((error_count + 1))
fi

if [ -z "${{ secrets.GITLAB_TRIGGER_URL }}" ]; then
echo "::error::GITLAB_TRIGGER_URL secret is not set"
error_count=$((error_count + 1))
fi

# Check required outputs from previous jobs
if [ -z "${{ needs.build-artifact.outputs.NC_VERSION }}" ]; then
echo "::error::NC_VERSION output from build-artifact job is not set"
error_count=$((error_count + 1))
else
echo "✓ NC_VERSION: ${{ needs.build-artifact.outputs.NC_VERSION }}"
fi

if [ -z "${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" ]; then
echo "::error::ARTIFACTORY_LAST_BUILD_PATH output from upload-to-artifactory job is not set"
error_count=$((error_count + 1))
else
echo "✓ ARTIFACTORY_LAST_BUILD_PATH: ${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}"
fi

# Check GitHub context variables
if [ -z "${{ github.sha }}" ]; then
echo "::error::github.sha is not set"
error_count=$((error_count + 1))
else
echo "✓ GITHUB_SHA: ${{ github.sha }}"
fi

if [ -z "${{ github.run_id }}" ]; then
echo "::error::github.run_id is not set"
error_count=$((error_count + 1))
else
echo "✓ BUILD_ID: ${{ github.run_id }}"
fi

if [ -z "${{ github.ref_name }}" ]; then
echo "::error::github.ref_name is not set"
error_count=$((error_count + 1))
else
echo "✓ BRANCH: ${{ github.ref_name }}"
fi

# Abort if any required variable is not set
if [ $error_count -ne 0 ]; then
echo "::error::Required variables are not set. Aborting."
exit 1
fi

echo "✅ All required variables are set"
- name: Trigger remote workflow
run: |
# Enable command echo for debugging purposes
set -x

# Determine build type based on branch:
# - 'ionos-dev' branch triggers 'dev' build type
# - 'ionos-stable' branch triggers 'stable' build type
# Branch to GitLab Trigger Mapping:
# | ref_name | GITLAB_REF | BUILD_TYPE |
# |--------------|--------------|-------------|
# | ionos-dev | main | dev |
# | ionos-stable | main | stable |
# | rc/* | main | rc |

BUILD_TYPE="dev"

# Override build type for stable branch
if [ "${{ github.ref_name }}" == "ionos-stable" ]; then
BUILD_TYPE="stable"
# Override build type for rc/* branches
elif [[ "${{ github.ref_name }}" =~ ^rc/ ]]; then
BUILD_TYPE="rc"
fi

# Construct source build URL for traceability
Expand All @@ -953,7 +1052,7 @@ jobs:
--fail-with-body \
-o response.json \
--form token=${{ secrets.GITLAB_TOKEN }} \
--form ref="stable" \
--form ref="main" \
--form "variables[GITHUB_SHA]=${{ github.sha }}" \
--form "variables[ARTIFACTORY_LAST_BUILD_PATH]=${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" \
--form "variables[NC_VERSION]=${{ needs.build-artifact.outputs.NC_VERSION }}" \
Expand Down