Skip to content
Merged
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
201 changes: 163 additions & 38 deletions .github/workflows/submodule-trigger-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2024 IONOS Productivity
# SPDX-License-Identifier: MIT
name: Trigger ncw-server submodule update
name: Create pre-release and update ncw-server submodule

on:
push:
Expand All @@ -13,62 +13,187 @@ permissions:
pull-requests: write

jobs:
get-commit-info:
runs-on: [self-hosted]
create-prerelease:
runs-on: [ubuntu-latest]
outputs:
sha: ${{ steps.commit-info.outputs.sha }}
short_sha: ${{ steps.commit-info.outputs.short_sha }}
message: ${{ steps.commit-info.outputs.message }}
author: ${{ steps.commit-info.outputs.author }}
tag_name: ${{ steps.commit-info.outputs.short_sha }}
release_url: ${{ steps.create-release.outputs.html_url }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 1
fetch-depth: 0

- name: Get commit information
id: commit-info
run: |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
echo "author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT

call-submodule-update:
needs: get-commit-info
runs-on: [self-hosted]

- name: Check GitHub CLI installation
id: check-gh
run: |
if command -v gh &> /dev/null; then
echo "installed=true" >> $GITHUB_OUTPUT
else
echo "installed=false" >> $GITHUB_OUTPUT
fi

- name: Install GitHub CLI
if: steps.check-gh.outputs.installed != 'true'
run: |
echo "Installing GitHub CLI..."
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y

- name: Create pre-release
id: create-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if the release already exists
if gh release view "${{ steps.commit-info.outputs.short_sha }}" --repo "${{ github.repository }}" > /dev/null 2>&1; then
# Release exists, get its URL
RELEASE_URL=$(gh release view "${{ steps.commit-info.outputs.short_sha }}" --repo "${{ github.repository }}" --json url -q ".url")
else
# Release does not exist, create it
RELEASE_URL=$(gh release create "${{ steps.commit-info.outputs.short_sha }}" \
--title "Pre-release ${{ steps.commit-info.outputs.short_sha }}" \
--generate-notes \
--prerelease \
--repo "${{ github.repository }}")
fi
echo "html_url=$RELEASE_URL" >> $GITHUB_OUTPUT

create-submodule-pr:
needs: create-prerelease
runs-on: [ubuntu-latest]
if: github.repository == 'IONOS-Productivity/ncw-config'

steps:
- name: Trigger ncw-server submodule update workflow
- name: Checkout ncw-server repository
uses: actions/checkout@v5
with:
repository: IONOS-Productivity/ncw-server
token: ${{ secrets.NCW_SERVER_PAT }}
ref: ionos-dev
fetch-depth: 1
sparse-checkout: |
IONOS
.gitmodules

- name: Check GitHub CLI installation
id: check-gh
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.SUBMODULE_UPDATE_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/IONOS-Productivity/ncw-server/dispatches \
-d '{
"event_type": "submodule-update",
"client_payload": {
"submodule_name": "IONOS",
"submodule_repo": "${{ github.repository }}",
"commit_sha": "${{ needs.get-commit-info.outputs.sha }}",
"commit_message": "${{ needs.get-commit-info.outputs.message }}",
"trigger_repo": "${{ github.repository }}",
"trigger_ref": "${{ github.ref }}"
}
}'
if command -v gh &> /dev/null; then
echo "installed=true" >> $GITHUB_OUTPUT
else
echo "installed=false" >> $GITHUB_OUTPUT
fi

- name: Install GitHub CLI
if: steps.check-gh.outputs.installed != 'true'
run: |
echo "Installing GitHub CLI..."
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y

- name: Update IONOS submodule
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Configure git to use HTTPS instead of SSH for GitHub
git config --global url."https://github.com/".insteadOf "[email protected]:"
git config --global url."https://".insteadOf "ssh://"
Comment on lines +116 to +117
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global Git URL rewrite configuration may not be necessary and could potentially cause issues. The actions/checkout@v5 action with the token parameter should already configure Git to use HTTPS with the provided PAT. These global rewrites (lines 110-111) might interfere with that configuration. Additionally, for the git submodule update --init command to work with private repositories, you may need to ensure the submodule URL in .gitmodules uses HTTPS, or configure Git credentials explicitly. Consider testing if these lines can be removed, or add explicit credential configuration if submodule authentication fails.

Suggested change
git config --global url."https://github.com/".insteadOf "[email protected]:"
git config --global url."https://".insteadOf "ssh://"

Copilot uses AI. Check for mistakes.

# Create a new branch for the update from ionos-dev
BRANCH_NAME="update-ionos-submodule-${{ needs.create-prerelease.outputs.short_sha }}"
git checkout -B "$BRANCH_NAME"

# Initialize only the IONOS submodule
git submodule update --init IONOS

# Update the submodule to the new commit
cd IONOS
git fetch origin main
git checkout ${{ needs.create-prerelease.outputs.sha }}

# Get the commit message for description
COMMIT_MSG=$(git log -1 --pretty=format:'%s')
cd ..

# Commit the submodule update with release link
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-prerelease.outputs.short_sha }}"
git add IONOS
git commit -m "IONOS(config): update submodule ${{ needs.create-prerelease.outputs.short_sha }} ($COMMIT_MSG)" \
-m "" \
-m "$RELEASE_URL" \
-m "" \
-m "Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

# Push the branch
git push origin "$BRANCH_NAME"

- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.NCW_SERVER_PAT }}
run: |
BRANCH_NAME="update-ionos-submodule-${{ needs.create-prerelease.outputs.short_sha }}"

# Get the commit message from IONOS submodule
cd IONOS
COMMIT_MSG=$(git log -1 --pretty=format:'%s')
cd ..
Comment on lines +132 to +156
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The COMMIT_MSG variable is retrieved twice (lines 126 and 149) from the IONOS submodule, which is redundant. Consider setting it once as an environment variable or output in the "Update IONOS submodule" step and reusing it in the "Create Pull Request" step to improve maintainability.

Copilot uses AI. Check for mistakes.

RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-prerelease.outputs.short_sha }}"
Comment on lines +136 to +158
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RELEASE_URL is constructed twice (lines 130 and 152) with identical logic. This duplication should be avoided. Consider constructing it once in the "Update IONOS submodule" step and exporting it as an environment variable or job output for reuse in the "Create Pull Request" step.

Copilot uses AI. Check for mistakes.

PR_BODY="IONOS(config): update submodule ${{ needs.create-prerelease.outputs.short_sha }} ($COMMIT_MSG)

$RELEASE_URL

---
Auto-generated PR from IONOS repository merge to main branch."

# Check if a PR already exists for this branch
EXISTING_PR_URL=$(gh pr list \
--repo IONOS-Productivity/ncw-server \
--head "$BRANCH_NAME" \
--state open \
--json url \
--jq '.[0].url')

if [ -n "$EXISTING_PR_URL" ]; then
PR_URL="$EXISTING_PR_URL"
echo "::notice::PR already exists: $PR_URL"
else
PR_URL=$(gh pr create \
--repo IONOS-Productivity/ncw-server \
--title "IONOS(config): update submodule ${{ needs.create-prerelease.outputs.short_sha }} ($COMMIT_MSG)" \
--body "$PR_BODY" \
--base ionos-dev \
--head "$BRANCH_NAME")
echo "::notice::Created PR: $PR_URL"
fi
log-details:
needs: [get-commit-info, call-submodule-update]
runs-on: [self-hosted]
needs: [create-prerelease, create-submodule-pr]
runs-on: [ubuntu-latest]
if: always()

steps:
- name: Log trigger details
- name: Log workflow details
run: |
echo "::notice::✅ Triggered ncw-server submodule update workflow"
echo "::notice::📦 Submodule: IONOS"
echo "::notice::🔗 Commit: ${{ needs.get-commit-info.outputs.sha }}"
echo "::notice::💬 Message: ${{ needs.get-commit-info.outputs.message }}"
echo "::notice::👤 Author: ${{ needs.get-commit-info.outputs.author }}"
echo "::notice::✅ Created pre-release with tag ${{ needs.create-prerelease.outputs.tag_name }}"
echo "::notice::🔗 Release URL: ${{ needs.create-prerelease.outputs.release_url }}"
if: needs.create-submodule-pr.result == 'success'
run: echo "::notice::📦 Submodule update PR created for ncw-server"
echo "::notice::💾 Commit: ${{ needs.create-prerelease.outputs.sha }}"