Skip to content

Commit b4bc31e

Browse files
authored
Merge pull request #22 from kitconcept/issues-21-13-19
Fix deploy hangs and env_file word-splitting, on a new test harness
2 parents f941c3e + e25c923 commit b4bc31e

31 files changed

Lines changed: 1001 additions & 16 deletions

‎.dockerignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ Dockerfile
55
docs
66
Makefile
77
README.md
8+
Dockerfile.test
9+
tests
10+
CHANGELOG.md
11+
news
12+
towncrier.toml

‎.github/dependabot.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
updates:
3+
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
# Check for updates to GitHub Actions every week
8+
interval: "weekly"
9+
# No `cooldown` here: it is not supported for the github-actions
10+
# ecosystem, so the weekly interval is the only pacing available.
11+
groups:
12+
# One pull request for all action bumps, so CI validates them together.
13+
github-actions:
14+
patterns:
15+
- "*"
16+
# Must already exist in the repository, otherwise it is silently ignored.
17+
# "skip changelog" is what exempts these pull requests from the changelog
18+
# workflow, which dependabot has no way of satisfying itself.
19+
labels:
20+
- "dependencies"
21+
- "skip changelog"
22+
23+
- package-ecosystem: "docker"
24+
# Keeps the pinned base image in Dockerfile current.
25+
directory: "/"
26+
schedule:
27+
interval: "weekly"
28+
cooldown:
29+
# Supported for the docker ecosystem: ignore releases younger than this.
30+
default-days: 7
31+
labels:
32+
- "dependencies"
33+
- "skip changelog"

‎.github/workflows/changelog.yml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Changelog"
2+
on:
3+
pull_request:
4+
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
5+
branches:
6+
- main
7+
8+
env:
9+
base-branch: main
10+
11+
permissions:
12+
contents: read
13+
pull-requests: read
14+
15+
jobs:
16+
17+
checks:
18+
runs-on: ubuntu-latest
19+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip changelog') }}
20+
steps:
21+
- uses: actions/checkout@v7
22+
with:
23+
# Fetch all history
24+
fetch-depth: '0'
25+
26+
- name: Setup uv
27+
uses: plone/meta/.github/actions/setup_uv@2.x
28+
with:
29+
python-version: "3.14"
30+
working-directory: '.'
31+
32+
- name: "Fetch base branch"
33+
run: |
34+
# Reference: https://github.com/actions/checkout/#fetch-all-branches.
35+
git fetch --no-tags origin ${{ env.base-branch }}
36+
37+
- name: "Repository: Check"
38+
id: repository-changelog
39+
run: |
40+
uvx towncrier check --compare-with origin/${{ env.base-branch }} --config ./towncrier.toml --dir ./
41+
42+
- name: "Report check"
43+
if: ${{ always() }}
44+
run: |
45+
echo '# Workflow Report' >> $GITHUB_STEP_SUMMARY
46+
echo '| Job ID | Conclusion |' >> $GITHUB_STEP_SUMMARY
47+
echo '| --- | --- |' >> $GITHUB_STEP_SUMMARY
48+
echo '| repository |${{ steps.repository-changelog.conclusion }} |' >> $GITHUB_STEP_SUMMARY

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
lint:
13+
name: Shellcheck
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- name: Checkout
18+
uses: actions/checkout@v7
19+
20+
- name: Lint shell scripts
21+
run: make lint
22+
23+
test:
24+
name: Bats
25+
runs-on: ubuntu-latest
26+
steps:
27+
28+
- name: Checkout
29+
uses: actions/checkout@v7
30+
31+
# Builds the action image, then the test runner on top of it, so the
32+
# suite runs against the same environment the action ships. This also
33+
# means a broken Dockerfile fails here instead of at release time.
34+
- name: Run test suite
35+
run: make test

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818

1919
- name: Checkout
20-
uses: actions/checkout@v5
20+
uses: actions/checkout@v7
2121

2222
- name: Docker meta
2323
id: meta

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change log
2+
3+
<!-- You should *NOT* be adding new change log entries to this file.
4+
You should create a file in the news directory instead.
5+
See the Development section of README.md for the fragment types and
6+
naming convention.
7+
-->
8+
9+
<!-- towncrier release notes start -->

‎Dockerfile.test‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Test runner image.
2+
#
3+
# It is built FROM the action image on purpose: the scripts depend on what that
4+
# image provides (bash, and GNU xargs from findutils rather than the busybox
5+
# one), so the suite has to run in the same environment the action ships.
6+
ARG BASE_IMAGE=ghcr.io/kitconcept/docker-stack-deploy:test
7+
FROM ${BASE_IMAGE}
8+
9+
RUN apk add --no-cache bats
10+
11+
WORKDIR /code
12+
13+
ENTRYPOINT [ "bats" ]
14+
CMD [ "tests/" ]

‎Makefile‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ MAKEFLAGS+=--no-builtin-rules
1111
BASE_NAME=docker-stack-deploy
1212
IMAGE_NAME=ghcr.io/kitconcept/$(BASE_NAME)
1313

14+
# Images used by the test suite, never pushed.
15+
TEST_IMAGE=$(IMAGE_NAME):test
16+
TEST_RUNNER_IMAGE=$(IMAGE_NAME):test-runner
17+
SHELLCHECK_IMAGE=koalaman/shellcheck:stable
18+
19+
# Everything shellcheck should look at.
20+
SHELL_SOURCES=scripts/docker-entrypoint.sh scripts/stack-wait.sh tests/helpers/bin/docker
21+
1422
# We like colors
1523
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
1624
RED=`tput setaf 1`
@@ -36,6 +44,26 @@ build-image: # Build Docker Image
3644
@echo "Building $(IMAGE_NAME)"
3745
docker build . -t $(IMAGE_NAME)
3846

47+
.PHONY: lint
48+
lint: # Lint the shell scripts with shellcheck
49+
docker run --rm -v "$(PWD)":/code -w /code $(SHELLCHECK_IMAGE) $(SHELL_SOURCES)
50+
51+
.PHONY: build-test-image
52+
build-test-image: # Build the bats test runner image
53+
docker build . -t $(TEST_IMAGE)
54+
docker build . -f Dockerfile.test --build-arg BASE_IMAGE=$(TEST_IMAGE) -t $(TEST_RUNNER_IMAGE)
55+
56+
.PHONY: test
57+
test: build-test-image # Run the bats test suite
58+
docker run --rm -v "$(PWD)":/code -w /code $(TEST_RUNNER_IMAGE) tests/
59+
60+
# Changelog
61+
.PHONY: draft-changelog
62+
draft-changelog: # Display the draft of the changelog
63+
@uvx towncrier build --draft --version unreleased --config towncrier.toml
64+
65+
# Release
66+
.PHONY: create-tag
3967
create-tag: # Create a new tag using git
4068
@test -n "$(VERSION)"
4169
if git show-ref --tags v$(VERSION) --quiet; \
@@ -44,6 +72,7 @@ create-tag: # Create a new tag using git
4472
else \
4573
echo "Creating new tag $(VERSION)"; \
4674
sed -i 's/$(BASE_NAME):latest/$(BASE_NAME):$(VERSION)/' action.yml; \
75+
uvx towncrier build --yes --version $(VERSION) --config towncrier.toml; \
4776
git commit -am "Prepare release $(VERSION)"; \
4877
git tag -a v$(VERSION) -m "Release $(VERSION)"; \
4978
git push && git push --tags; \

‎README.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,51 @@ Please **DO NOT** commit to version branches directly. Even for the smallest and
201201

202202
**ALWAYS** open a pull request and ask somebody else to merge your code. **NEVER** merge it yourself.
203203

204+
### Development
205+
206+
Both commands need Docker, and nothing else — there is no local toolchain to install.
207+
208+
```shell
209+
make lint # shellcheck the shell scripts
210+
make test # run the bats suite
211+
```
212+
213+
`make test` builds the action image and then builds the test runner on top of
214+
it, so the suite runs in the same environment the action ships. That matters:
215+
the scripts rely on GNU `xargs` from `findutils`, and against the busybox
216+
`xargs` in a plain Alpine image the tests fail for reasons that have nothing to
217+
do with the code.
218+
219+
Tests live in `tests/` and use a fake `docker` CLI (`tests/helpers/bin/docker`)
220+
that replays a scenario from `tests/fixtures/*.services`, so no Swarm is
221+
needed. Each fixture describes one poll of the wait loop per section.
222+
223+
Tests that document a currently open bug call `skip` with a link to the issue.
224+
They are written to assert the *desired* behaviour, so fixing the bug means
225+
deleting the `skip` line rather than writing a new test.
226+
227+
### Change log
228+
229+
`CHANGELOG.md` is generated by [towncrier](https://towncrier.readthedocs.io/) —
230+
do not edit it directly. Add a file to `news/` instead, named for the issue it
231+
addresses, and CI will check that every pull request has one.
232+
233+
```
234+
news/21.bugfix # an issue number, when there is an issue
235+
news/+test-harness.internal # a short slug, when there is not
236+
```
237+
238+
Types are `breaking`, `feature`, `bugfix`, `internal` and `documentation`. Write
239+
one sentence in the past tense, describing the change from the user's side, and
240+
sign it with your GitHub handle:
241+
242+
```
243+
Fixed `env_file` values containing spaces being truncated. @ericof
244+
```
245+
246+
Preview the result with `uvx towncrier build --draft --version <next>`. A pull
247+
request that genuinely needs no entry can carry the `skip changelog` label.
248+
204249
205250
## Credits
206251

‎news/+test-harness.internal‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a bats test suite for the shell scripts, run in CI together with shellcheck. @ericof

0 commit comments

Comments
 (0)