Skip to content
Open
Show file tree
Hide file tree
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
83 changes: 75 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,20 @@ BRANCH_NAME=${env.BRANCH_NAME}"""

withBuildVars(props) {
echo 'Building Angular application'
echo "Using base version: ${BASE_VERSION}"
echo "Using git hash: ${GIT_COMMIT_HASH}"
echo "Using image tag: ${IMAGE_TAG}"

// Replace placeholders
sh """
sed -i "s/VERSION_PLACEHOLDER/${BASE_VERSION}/g" src/environments/environment.prod.ts
sed -i "s/VERSION_PLACEHOLDER/${BASE_VERSION}/g" src/environments/environment.staging.ts
sed -i "s/VERSION_PLACEHOLDER/${BASE_VERSION}/g" src/environments/environment.alpha.ts
sed -i "s/GIT_HASH_PLACEHOLDER/${GIT_COMMIT_HASH}/g" src/environments/environment.prod.ts
sed -i "s/GIT_HASH_PLACEHOLDER/${GIT_COMMIT_HASH}/g" src/environments/environment.staging.ts
sed -i "s/GIT_HASH_PLACEHOLDER/${GIT_COMMIT_HASH}/g" src/environments/environment.alpha.ts
"""

sh 'npm run build'
sh 'ls -la dist/'
}
Expand Down Expand Up @@ -780,33 +784,96 @@ BRANCH_NAME=${env.BRANCH_NAME}"""
container('builder'){
script {
def props = loadBuildVars()

withBuildVars(props) {
echo "Deploying to Production: ${IMAGE_TAG}"

// Validate configmap
sh '''
kubectl get configmap elohim-config-prod -n ethosengine || {
echo "❌ ERROR: elohim-config-prod ConfigMap missing"
exit 1
}
'''

// Deploy

// Update deployment manifest
sh "sed 's/BUILD_NUMBER_PLACEHOLDER/${IMAGE_TAG}/g' manifests/prod-deployment.yaml > manifests/prod-deployment-${IMAGE_TAG}.yaml"
sh "sed 's/BUILD_NUMBER_PLACEHOLDER/${IMAGE_TAG}/g' manifests/prod-deployment.yaml > manifests/prod-deployment-${IMAGE_TAG}.yaml"
sh "kubectl apply -f manifests/prod-deployment-${IMAGE_TAG}.yaml"
sh "kubectl rollout restart deployment/elohim-site -n ethosengine"
sh 'kubectl rollout status deployment/elohim-site -n ethosengine --timeout=300s'

echo 'Production deployment completed!'
}
}
}
}
}

stage('Create GitHub Release') {
when {
branch 'main'
}
steps {
container('builder'){
script {
def props = loadBuildVars()

withBuildVars(props) {
echo "Creating GitHub release for version: v${BASE_VERSION}"

withCredentials([usernamePassword(credentialsId: 'github-pat', passwordVariable: 'GITHUB_TOKEN', usernameVariable: 'GITHUB_USERNAME')]) {
sh """#!/bin/bash
set -euo pipefail

# Configure git
git config --global --add safe.directory "*"

# Check if release already exists
RELEASE_EXISTS=\$(curl -s -o /dev/null -w "%{http_code}" \\
-H "Authorization: token \${GITHUB_TOKEN}" \\
"https://api.github.com/repos/ethosengine/elohim/releases/tags/v${BASE_VERSION}")

if [ "\$RELEASE_EXISTS" = "200" ]; then
echo "Release v${BASE_VERSION} already exists, skipping creation"
exit 0
fi

# Create annotated tag
git tag -a "v${BASE_VERSION}" -m "Release version ${BASE_VERSION}" ${GIT_COMMIT_HASH} || {
echo "Tag v${BASE_VERSION} may already exist locally, continuing..."
}

# Push tag to GitHub
git push https://\${GITHUB_TOKEN}@github.com/ethosengine/elohim.git "v${BASE_VERSION}" || {
echo "Tag push failed, may already exist remotely"
}

# Create release via GitHub API
RELEASE_NOTES="## Release v${BASE_VERSION}\\n\\nDeployed to production on \$(date -u +"%Y-%m-%d %H:%M:%S UTC")\\n\\n**Commit:** ${GIT_COMMIT_HASH}\\n**Image Tag:** ${IMAGE_TAG}"

curl -X POST \\
-H "Authorization: token \${GITHUB_TOKEN}" \\
-H "Accept: application/vnd.github.v3+json" \\
"https://api.github.com/repos/ethosengine/elohim/releases" \\
-d "{\\
\\"tag_name\\": \\"v${BASE_VERSION}\\",\\
\\"name\\": \\"Release v${BASE_VERSION}\\",\\
\\"body\\": \\"\${RELEASE_NOTES}\\",\\
\\"draft\\": false,\\
\\"prerelease\\": false\\
}"

echo "✅ GitHub release v${BASE_VERSION} created successfully"
"""
}
}
}
}
}
}

stage('Cleanup') {
steps {
container('builder'){
Expand Down
1 change: 1 addition & 0 deletions elohim-app/src/app/components/footer/footer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

<!-- Build Info -->
<div class="build-info">
<a [href]="githubReleaseUrl" data-cy="release-version" class="git-hash" target="_blank" rel="noopener noreferrer" [attr.aria-label]="'View release on GitHub'">v{{ version }}</a>
<a [href]="githubCommitUrl" data-cy="git-hash" class="git-hash" target="_blank" rel="noopener noreferrer" [attr.aria-label]="'View commit ' + gitHash + ' on GitHub'">{{ gitHash }}</a>
</div>

Expand Down
17 changes: 17 additions & 0 deletions elohim-app/src/app/components/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,32 @@ describe('FooterComponent', () => {
expect(component).toBeTruthy();
});

it('should initialize version from environment', () => {
expect(component.version).toBe(environment.version);
});

it('should initialize gitHash from environment', () => {
expect(component.gitHash).toBe(environment.gitHash);
});

it('should construct githubReleaseUrl with version', () => {
const expectedUrl = `https://github.com/ethosengine/elohim/releases/v${environment.version}`;
expect(component.githubReleaseUrl).toBe(expectedUrl);
});

it('should construct githubCommitUrl with gitHash', () => {
const expectedUrl = `https://github.com/ethosengine/elohim/commit/${environment.gitHash}`;
expect(component.githubCommitUrl).toBe(expectedUrl);
});

it('should render release version link in template', () => {
const compiled = fixture.nativeElement;
const releaseLink = compiled.querySelector('[data-cy="release-version"]');
expect(releaseLink).toBeTruthy();
expect(releaseLink.textContent.trim()).toBe(`v${environment.version}`);
expect(releaseLink.getAttribute('href')).toBe(component.githubReleaseUrl);
});

it('should render git hash link in template', () => {
const compiled = fixture.nativeElement;
const gitHashLink = compiled.querySelector('[data-cy="git-hash"]');
Expand Down
2 changes: 2 additions & 0 deletions elohim-app/src/app/components/footer/footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { environment } from '../../../environments/environment';
styleUrl: './footer.component.css'
})
export class FooterComponent {
version = environment.version;
gitHash = environment.gitHash;
githubReleaseUrl = `https://github.com/ethosengine/elohim/releases/v${environment.version}`;
githubCommitUrl = `https://github.com/ethosengine/elohim/commit/${environment.gitHash}`;
}
1 change: 1 addition & 0 deletions elohim-app/src/environments/environment.alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const environment = {
production: false,
logLevel: 'debug' as 'debug' | 'info' | 'error',
environment: 'alpha',
version: 'VERSION_PLACEHOLDER',
gitHash: 'GIT_HASH_PLACEHOLDER'
};
1 change: 1 addition & 0 deletions elohim-app/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const environment = {
production: true,
logLevel: 'error' as 'debug' | 'info' | 'error',
environment: 'production',
version: 'VERSION_PLACEHOLDER',
gitHash: 'GIT_HASH_PLACEHOLDER'
};
1 change: 1 addition & 0 deletions elohim-app/src/environments/environment.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const environment = {
production: false,
logLevel: 'debug' as 'debug' | 'info' | 'error',
environment: 'staging',
version: 'VERSION_PLACEHOLDER',
gitHash: 'GIT_HASH_PLACEHOLDER'
};
1 change: 1 addition & 0 deletions elohim-app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const environment = {
production: false,
logLevel: 'debug' as 'debug' | 'info' | 'error',
environment: 'development',
version: '1.0.0-dev',
gitHash: 'local-dev'
};