Skip to content

Commit db4d48e

Browse files
committed
Cleaned up tasks and shell scripts
1 parent 96f87a1 commit db4d48e

File tree

6 files changed

+135
-48
lines changed

6 files changed

+135
-48
lines changed

.github/workflows/documentation.yaml

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,54 @@ jobs:
4040
repo-token: ${{ secrets.GITHUB_TOKEN }}
4141
- run: |
4242
task github-actions:template-headers:update --yes
43-
# Check that files hav not changed.
43+
# Check that files have not changed.
4444
- run: |
45-
git diff --exit-code github/workflows/
45+
git diff --exit-code
46+
47+
check-config-file-headers:
48+
runs-on: ubuntu-latest
49+
name: Check that config file headers are up to date
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: arduino/setup-task@v2
53+
with:
54+
repo-token: ${{ secrets.GITHUB_TOKEN }}
55+
- run: |
56+
task github-actions:config-headers:update --yes
57+
# Check that files have not changed.
58+
- run: |
59+
git diff --exit-code
60+
61+
check-links:
62+
runs-on: ubuntu-latest
63+
name: Check that workflow and config file links are up to date
64+
steps:
65+
- uses: actions/checkout@v4
66+
- uses: arduino/setup-task@v2
67+
with:
68+
repo-token: ${{ secrets.GITHUB_TOKEN }}
69+
- run: |
70+
task github-actions:link --yes
71+
# Check that files have not changed.
72+
- run: |
73+
git diff --exit-code
74+
75+
lint-markdown:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v4
79+
- uses: arduino/setup-task@v2
80+
with:
81+
repo-token: ${{ secrets.GITHUB_TOKEN }}
82+
- run: |
83+
SKIP_FIX=1 task lint:markdown
84+
85+
lint-shell-script:
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: arduino/setup-task@v2
90+
with:
91+
repo-token: ${{ secrets.GITHUB_TOKEN }}
92+
- run: |
93+
SKIP_FIX=1 task lint:shell-script

Taskfile.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ tasks:
2929
GLOB: >-
3030
{{.CLI_ARGS | default "'**/*.md'"}}
3131
32+
lint:shell-script:
33+
desc: "Lint shell scripts"
34+
cmds:
35+
# https://github.com/koalaman/shellcheck?tab=readme-ov-file#installing
36+
- docker run --rm --volume "$PWD:"/mnt koalaman/shellcheck:stable {{.GLOB}}
37+
vars:
38+
# We use a block scalar (https://yaml-multiline.info/#block-scalars) here to make escaping (a little) easier.
39+
GLOB: >-
40+
{{.CLI_ARGS | default "task/scripts/*"}}
41+
3242
default:
3343
cmds:
3444
- task --list

task/Taskfile.github-actions.yml

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,54 +38,17 @@ tasks:
3838
prompt: "Updating headers may break things, so check result afterwards. Really update headers?"
3939
desc: "Update headers in GitHub Actions templates"
4040
cmds:
41-
- |
42-
for f in $(find github/workflows/ -name '*.yaml'); do
43-
echo "$f"
44-
# If file starts with `# ` …
45-
if [[ $(head --lines=1 "$f") =~ "^# " ]]; then
46-
# … replace the header.
47-
# This is done by deleting all lines from the top of the file to a blank line.
48-
docker run --rm --volume=$PWD:/app --user ${COMPOSE_USER:-deploy} itkdev/php8.4-fpm:latest sed -i '1,/^$/d' "$f"
49-
fi
50-
51-
# Write header and file into temporary file.
52-
(
53-
echo "# Do not edit this file! Make a pull request on changing"
54-
echo "# $f in"
55-
echo "# https://github.com/itk-dev/devops_itkdev-docker if need be."
56-
echo ""
57-
cat "$f"
58-
) > "$f.tmp"
59-
# Replace original file with temporary file.
60-
mv "$f.tmp" "$f"
61-
done
41+
- task: run-script
42+
vars:
43+
SCRIPT: template-headers-update
6244

6345
config-headers:update:
6446
prompt: "Updating headers may break things, so check result afterwards. Really update headers?"
6547
desc: "Update headers in tool config"
6648
cmds:
67-
- 'echo TODO: implement {{.TASK}}'
68-
# - |
69-
# for f in $(find config -type f); do
70-
# echo "$f"
71-
# # # If file starts with `# ` …
72-
# # if [[ $(head --lines=1 "$f") =~ "^# " ]]; then
73-
# # # … replace the header.
74-
# # # This is done by deleting all lines from the top of the file to a blank line.
75-
# # docker run --rm --volume=$PWD:/app --user ${COMPOSE_USER:-deploy} itkdev/php8.4-fpm:latest sed -i '1,/^$/d' "$f"
76-
# # fi
77-
78-
# # Write header and file into temporary file.
79-
# (
80-
# echo "# This file is copied from $f in https://github.com/itk-dev/devops_itkdev-docker."
81-
# echo "#"
82-
# echo "# Feel free to edit the file, but consider making a pull request if you find a general issue with the file."
83-
# echo ""
84-
# cat "$f"
85-
# ) > "$f.tmp"
86-
# # Replace original file with temporary file.
87-
# mv "$f.tmp" "$f"
88-
# done
49+
- task: run-script
50+
vars:
51+
SCRIPT: config-headers-update
8952

9053
link:
9154
desc: "Set up symlinks"

task/scripts/config-headers-update

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
project_dir=$(cd "$(dirname "$script_dir")/.." && pwd)
5+
6+
cd "$project_dir" || exit
7+
8+
# shellcheck disable=SC2044
9+
for f in $(find config -type f); do
10+
echo "$f"
11+
12+
# Remove exiting header.
13+
# This is done by deleting all lines from the top of the file to a blank line.
14+
sed -i '1,/^$/d' "$f"
15+
16+
comment_prefix=''
17+
comment_start='# '
18+
comment_end=''
19+
if [[ "$f" =~ \.php(\.dist)?$ ]]; then
20+
comment_prefix='<?php'
21+
comment_start='// '
22+
comment_end=''
23+
elif [[ "$f" =~ \.jsonc$ ]]; then
24+
comment_start='// '
25+
comment_end=''
26+
elif [[ "$f" =~ \.xml(\.dist)?$ ]]; then
27+
comment_start='<!-- '
28+
comment_end=' -->'
29+
fi
30+
# Write header and file into temporary file.
31+
(
32+
[[ -n "${comment_prefix}" ]] && echo "${comment_prefix}"
33+
echo "${comment_start}This file is copied from $f in https://github.com/itk-dev/devops_itkdev-docker.${comment_end}"
34+
echo "${comment_start}Feel free to edit the file, but consider making a pull request if you find a general issue with the file.${comment_end}"
35+
echo ""
36+
cat "$f"
37+
) > "$f.tmp"
38+
# Replace original file with temporary file.
39+
mv "$f.tmp" "$f"
40+
done

task/scripts/github-actions-link

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function strip-project-type() {
1515
name="${BASH_REMATCH[2]}"
1616
fi
1717

18-
echo $name
18+
echo "$name"
1919
}
2020

2121
find templates -type l -delete
@@ -41,11 +41,11 @@ for template_dir in templates/*; do
4141
# Note: / is NOT a regex delimiter here, but an actual /, i.e. a directory separator.
4242
if [[ "$f" =~ /drupal/ ]]; then
4343
if [[ "$project_type" == "drupal" ]]; then
44-
source_file_name="$(basename $(dirname "$f"))/$(basename "$f")"
44+
source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")"
4545
fi
4646
elif [[ "$f" =~ /symfony/ ]]; then
4747
if [[ "$project_type" == "symfony" ]]; then
48-
source_file_name="$(basename $(dirname "$f"))/$(basename "$f")"
48+
source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")"
4949
fi
5050
else
5151
source_file_name=$(basename "$f")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
project_dir=$(cd "$(dirname "$script_dir")/.." && pwd)
5+
6+
cd "$project_dir" || exit
7+
8+
# shellcheck disable=SC2044
9+
for f in $(find github/workflows/ -name '*.yaml'); do
10+
echo "$f"
11+
12+
# Remove exiting header.
13+
# This is done by deleting all lines from the top of the file to a blank line.
14+
sed -i '1,/^$/d' "$f"
15+
16+
# Write header and file into temporary file.
17+
(
18+
echo "# Do not edit this file! Make a pull request on changing"
19+
echo "# $f in"
20+
echo "# https://github.com/itk-dev/devops_itkdev-docker if need be."
21+
echo ""
22+
cat "$f"
23+
) > "$f.tmp"
24+
# Replace original file with temporary file.
25+
mv "$f.tmp" "$f"
26+
done

0 commit comments

Comments
 (0)