Skip to content

Commit 6bda74b

Browse files
authored
Add initial configuration
1 parent d79f9db commit 6bda74b

File tree

15 files changed

+725
-1
lines changed

15 files changed

+725
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Simple Bash Action'
2+
description: 'A simple bash-based action that processes input and produces output'
3+
4+
inputs:
5+
name:
6+
description: 'Name to greet'
7+
required: true
8+
greeting:
9+
description: 'Greeting to use'
10+
required: false
11+
default: 'Hello'
12+
format:
13+
description: 'Output format (text/json)'
14+
required: false
15+
default: 'text'
16+
17+
outputs:
18+
message:
19+
description: 'The greeting message'
20+
time:
21+
description: 'Time when the greeting was generated'
22+
23+
runs:
24+
using: 'composite'
25+
steps:
26+
- name: Generate greeting
27+
shell: bash
28+
run: |
29+
# Get current time
30+
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
31+
32+
# Generate message
33+
MESSAGE="${{ inputs.greeting }}, ${{ inputs.name }}!"
34+
35+
# Format output based on input
36+
if [ "${{ inputs.format }}" == "json" ]; then
37+
echo "Output in JSON format:"
38+
echo "{\"message\": \"$MESSAGE\", \"time\": \"$CURRENT_TIME\"}"
39+
else
40+
echo "Output in text format:"
41+
echo "$MESSAGE"
42+
fi
43+
44+
# Set outputs
45+
echo "message=$MESSAGE" >> $GITHUB_OUTPUT
46+
echo "time=$CURRENT_TIME" >> $GITHUB_OUTPUT
47+
48+
# Add to step summary
49+
echo "### Greeting Generated" >> $GITHUB_STEP_SUMMARY
50+
echo "- Message: $MESSAGE" >> $GITHUB_STEP_SUMMARY
51+
echo "- Time: $CURRENT_TIME" >> $GITHUB_STEP_SUMMARY
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: File Transform and Upload
2+
description: Deploy an application specification to a Kubernetes cluster
3+
inputs:
4+
source-directory:
5+
description: Directory containing the source files to copy
6+
required: true
7+
target-directory:
8+
description: Directory to copy the files
9+
required: true
10+
clean-target-directory:
11+
description: Whether to clean the application directory before copying new files
12+
required: true
13+
default: true
14+
organization:
15+
description: GitHub organization where the GitOps repository is located
16+
required: true
17+
repository:
18+
description: Name of the GitHub repository
19+
required: true
20+
ref:
21+
description: Ref to deploy to files to
22+
required: true
23+
version:
24+
description: New version of the app
25+
required: true
26+
github-app-id:
27+
description: GitHub App ID used for reading helm chart
28+
required: true
29+
github-app-private-key:
30+
description: GitHub App Private Key used for reading helm chart
31+
required: true
32+
33+
runs:
34+
using: composite
35+
steps:
36+
- name: Get token for GitOps repository checkout
37+
id: token
38+
uses: getsentry/action-github-app-token@v2
39+
with:
40+
app_id: ${{ inputs.github-app-id }}
41+
private_key: ${{ inputs.github-app-private-key }}
42+
scope: ${{ inputs.organization }}
43+
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
with:
47+
path: app-repo
48+
49+
- name: Checkout target repository
50+
uses: actions/checkout@v4
51+
with:
52+
repository: ${{ inputs.organization }}/${{ inputs.repository }}
53+
token: ${{ steps.token.outputs.token }}
54+
ref: ${{ inputs.ref }}
55+
path: target-repo
56+
57+
- name: Clean target directory
58+
if: ${{ inputs.clean-app-directory == 'true' }}
59+
shell: bash
60+
run: |
61+
rm -rf ${{ github.workspace }}/target-repo/${{ inputs.target-directory }}/*
62+
63+
- name: Transform files
64+
shell: bash
65+
run: |
66+
bash ${{ github.action_path }}/transform.sh \
67+
--target-dir ${{ github.workspace }}/app-repo/${{ inputs.source-directory }} \
68+
--version ${{ inputs.version }}
69+
70+
- name: Copy files
71+
shell: bash
72+
run: |
73+
bash ${{ github.action_path }}/upload.sh \
74+
--source-dir ${{ github.workspace }}/app-repo/${{ inputs.source-directory }} \
75+
--target-dir ${{ github.workspace }}/target-repo/${{ inputs.target-directory }} \
76+
--branch ${{ inputs.ref }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Usage:
4+
# ./transform.sh --target-dir <directory> --version <value>
5+
#
6+
# Example:
7+
# ./transform.sh --target-dir ./myfiles --image-value 1.0.0-release.123
8+
#
9+
10+
set -eu
11+
12+
# Default argument values
13+
TARGET_DIR=""
14+
VERSION=""
15+
16+
# Parse arguments
17+
while [[ $# -gt 0 ]]; do
18+
case $1 in
19+
--target-dir)
20+
TARGET_DIR="$2"
21+
shift 2
22+
;;
23+
--version)
24+
VERSION="$2"
25+
shift 2
26+
;;
27+
*)
28+
echo "Unknown argument: $1"
29+
exit 1
30+
;;
31+
esac
32+
done
33+
34+
if [[ -z "$TARGET_DIR" || -z "$VERSION" ]]; then
35+
echo "Usage: $0 --target-dir <dir> --version <value>"
36+
exit 1
37+
fi
38+
39+
echo "-- Transforming files ----"
40+
# Get a list of all .yml or .yaml files in the source directory
41+
files=($(find "$TARGET_DIR" -type f \( -name "*.yml" -o -name "*.yaml" \)))
42+
43+
# If the file contains a spec.version field
44+
# Update it with the provided value
45+
for file in "${files[@]}"; do
46+
echo "-- Updating spec.version in $file ----"
47+
yq -e '.spec.version' "$file" >/dev/null 2>&1 && \
48+
yq -i '.spec.version = "'"${VERSION}"'"' "$file" || true
49+
done
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
# Usage:
4+
# ./upload.sh --source-dir <directory> --target-dir <directory> --branch <branch-name>
5+
#
6+
# Example:
7+
# ./upload.sh --source-dir ./project --target-dir ./myfiles --branch main
8+
#
9+
10+
set -eu
11+
12+
# Default argument values
13+
WORKSPACE=""
14+
SOURCE_DIRECTORY=""
15+
TARGET_DIRECTORY=""
16+
17+
# Parse arguments
18+
while [[ $# -gt 0 ]]; do
19+
case $1 in
20+
--branch)
21+
BRANCH_REF="$2"
22+
shift 2
23+
;;
24+
--source-dir)
25+
SOURCE_DIRECTORY="$2"
26+
shift 2
27+
;;
28+
--target-dir)
29+
TARGET_DIRECTORY="$2"
30+
shift 2
31+
;;
32+
*)
33+
echo "Unknown argument: $1"
34+
exit 1
35+
;;
36+
esac
37+
done
38+
39+
if [[ -z "$BRANCH_REF" || -z "$SOURCE_DIRECTORY" || -z "$TARGET_DIRECTORY" ]]; then
40+
echo "Usage: $0 --source-dir <dir> --target-dir <dir> --branch <value>"
41+
exit 1
42+
fi
43+
44+
mkdir -p ${TARGET_DIRECTORY}
45+
cp -r ${SOURCE_DIRECTORY}/* ${TARGET_DIRECTORY}/
46+
47+
git config user.email "actions@github.com"
48+
git config user.name "GitHub Actions"
49+
git config pull.rebase true
50+
51+
# Define variables for retry
52+
max_attempts=3
53+
attempt=1
54+
retry_delay=5 # in seconds
55+
56+
while [[ $attempt -le $max_attempts ]]; do
57+
git add -A $TARGET_DIRECTORY
58+
59+
if git diff --quiet ${BRANCH_REF} ${TARGET_DIRECTORY}/; then
60+
echo "No changes detected in files"
61+
break
62+
else
63+
echo "Changes detected in files"
64+
git commit -m "Update files"
65+
fi
66+
67+
if git pull && git push; then
68+
echo "Commit and push succesful to ${BRANCH_REF} branch"
69+
break
70+
else
71+
echo "Attempt $attempt failed, retrying in $retry_delay seconds..."
72+
sleep $retry_delay
73+
attempt=$((attempt + 1))
74+
fi
75+
done
76+
77+
if [[ $attempt -gt $max_attempts ]]; then
78+
echo "Exceeded maximum attempts to push changes, giving up"
79+
exit 1
80+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Deploy App
2+
description: Composite action to deploy an app
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Deploy
8+
shell: bash
9+
run: |
10+
echo "This is a placeholder action"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Go Build and Test
2+
description: Composite action to build and test a Go project
3+
4+
inputs:
5+
build-command:
6+
description: Command to build the Go project
7+
required: false
8+
default: go build ./...
9+
10+
outputs:
11+
build-status:
12+
description: Status of the build step
13+
value: ${{ steps.build.outcome }}
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '>=1.24'
22+
23+
- name: Build project
24+
id: build
25+
shell: bash
26+
run: |
27+
echo "Building project with command: ${{ inputs.build-command }}"
28+
${{ inputs.build-command }}
29+
30+
- name: Build summary
31+
shell: bash
32+
run: |
33+
echo "### Go Build Summary" >> $GITHUB_STEP_SUMMARY
34+
echo "- Build Status: ${{ steps.build.outcome }}" >> $GITHUB_STEP_SUMMARY
35+
if [[ "${{ inputs.upload-coverage }}" == "true" ]]; then
36+
echo "- Coverage File: ${{ inputs.coverage-file }}" >> $GITHUB_STEP_SUMMARY
37+
fi
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Go Build and Test
2+
description: Composite action to build and test a Go project
3+
4+
inputs:
5+
test-command:
6+
description: Command to run Go tests
7+
required: false
8+
default: go test ./... -v
9+
upload-coverage:
10+
description: Upload test coverage report
11+
required: false
12+
default: 'false'
13+
coverage-file:
14+
description: Coverage output file
15+
required: false
16+
default: coverage.out
17+
18+
outputs:
19+
test-status:
20+
description: Status of the test step
21+
value: ${{ steps.test.outcome }}
22+
23+
runs:
24+
using: composite
25+
steps:
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: '>=1.24'
30+
31+
- name: Run tests
32+
id: test
33+
shell: bash
34+
run: |
35+
echo "Running tests with command: ${{ inputs.test-command }}"
36+
# Run tests and produce coverage if requested
37+
if [[ "${{ inputs.upload-coverage }}" == "true" ]]; then
38+
${{ inputs.test-command }} -coverprofile=${{ inputs.coverage-file }}
39+
else
40+
${{ inputs.test-command }}
41+
fi
42+
43+
- name: Upload coverage
44+
if: inputs.upload-coverage == 'true' && steps.test.outcome == 'success'
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: go-coverage-report
48+
path: ${{ inputs.coverage-file }}
49+
retention-days: 30
50+
51+
- name: Build summary
52+
shell: bash
53+
run: |
54+
echo "### Go Test Summary" >> $GITHUB_STEP_SUMMARY
55+
echo "- Test Status: ${{ steps.test.outcome }}" >> $GITHUB_STEP_SUMMARY
56+
if [[ "${{ inputs.upload-coverage }}" == "true" ]]; then
57+
echo "- Coverage File: ${{ inputs.coverage-file }}" >> $GITHUB_STEP_SUMMARY
58+
fi

0 commit comments

Comments
 (0)