-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_dockerfile_options.sh
More file actions
executable file
·40 lines (31 loc) · 1.47 KB
/
update_dockerfile_options.sh
File metadata and controls
executable file
·40 lines (31 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
set -euo pipefail
# ###########################################################################
# PURPOSE:
# This script updates the GitHub Actions workflow file to reflect the
# current set of Dockerfile options available in the repository.
# It scans for Dockerfile.* files, extracts their suffixes, and updates
# the workflow YAML file accordingly.
# ###########################################################################
WORKFLOW_FILE_GITHUB=".github/workflows/build-docker-image.yml"
WORKFLOW_FILE_GITEA=".gitea/workflows/build-docker-image.yml"
# Ensure yq is installed
if ! command -v yq >/dev/null 2>&1; then
echo "Error: yq is not installed. Install it from https://github.com/mikefarah/yq"
exit 1
fi
# Find Dockerfile suffixes (e.g., 'base' from 'Dockerfile.base')
dockerfile_options=$(find . -maxdepth 1 -name "Dockerfile.*" \
| sed 's|./Dockerfile\.||' \
| sort)
if [ -z "$dockerfile_options" ]; then
echo "No Dockerfile.* files found in current directory."
exit 0
fi
echo "Updating workflow options with: $dockerfile_options"
# Convert newline list into a JSON array for yq
json_array=$(printf '%s\n' $dockerfile_options | jq -R . | jq -s .)
# Update the workflow YAML file
yq -i ".on.workflow_dispatch.inputs.dockerfile.options = $json_array" "$WORKFLOW_FILE_GITHUB"
yq -i ".on.workflow_dispatch.inputs.dockerfile.options = $json_array" "$WORKFLOW_FILE_GITEA"
echo "Updated $WORKFLOW_FILE_GITHUB with dockerfile options: $dockerfile_options"