Skip to content

Commit ffee83a

Browse files
stasadevclaude
andauthored
fix: fail the build step on errors and authenticate GitHub API calls (#41)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent be5b68b commit ffee83a

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ jobs:
5151
file-path: "${{ github.workspace }}/tests/bats-file"
5252
-
5353
name: "Test ddev ${{ matrix.version }} image"
54-
shell: 'script -q -e -c "bash {0}"'
54+
shell: 'script -q -e -c "bash -e {0}"'
5555
env:
5656
BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5758
run: |
5859
sudo snap install yq
5960
./build.sh -v ${{ matrix.version }} -l
@@ -67,7 +68,9 @@ jobs:
6768
password: ${{ secrets.GITHUB_TOKEN }}
6869
-
6970
name: "Build ddev ${{ matrix.version }} multi-arch image"
70-
shell: 'script -q -e -c "bash {0}"'
71+
shell: 'script -q -e -c "bash -e {0}"'
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7174
run: |
7275
docker buildx create --use --platform=linux/arm64,linux/amd64
7376
./build.sh -v ${{ matrix.version }} -x -p ${{ inputs.force_rebuild && '-f' || '' }}

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ jobs:
4141
file-path: "${{ github.workspace }}/tests/bats-file"
4242
-
4343
name: "Test ddev ${{ matrix.version }} image"
44-
shell: 'script -q -e -c "bash {0}"'
44+
shell: 'script -q -e -c "bash -e {0}"'
4545
env:
4646
BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }}
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4748
run: |
4849
sudo snap install yq
4950
./build.sh -v ${{ matrix.version }} -l

‎build.sh‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ help() {
1616
echo " * f - Force build and push even if the tag already exists in the registry"
1717
}
1818

19+
# Authenticate when GITHUB_TOKEN is set to avoid the low anonymous API rate limit
20+
github_api() {
21+
local auth=()
22+
if [[ -n "$GITHUB_TOKEN" ]]; then
23+
auth=(-H "Authorization: Bearer $GITHUB_TOKEN")
24+
fi
25+
curl --silent --show-error --fail -L -H "Accept: application/vnd.github+json" "${auth[@]}" "https://api.github.com/$1"
26+
}
27+
1928
# 'latest' always rebuilds; other tags skip if already pushed, unless forced.
2029
tagAlreadyExists() {
2130
if [[ "$OPTION_VERSION" == "latest" ]] || [[ -n "$FORCE" ]] || [[ -z "$PUSH" ]]; then
@@ -27,7 +36,7 @@ tagAlreadyExists() {
2736

2837
loadVersionAndTags() {
2938
# @todo: Currently limited to 99 releases, may use pagination
30-
ddev_releases=($(curl --silent -L -H "Accept: application/vnd.github+json" https://api.github.com/repos/${GITHUB_OWNER}/ddev/releases?per_page=99 | jq -r '.[].tag_name'))
39+
ddev_releases=($(github_api "repos/${GITHUB_OWNER}/ddev/releases?per_page=99" | jq -r '.[].tag_name'))
3140

3241
IFS='.' read -r -a version <<< "$OPTION_VERSION"
3342
bugfix_release="${version[2]}"
@@ -91,7 +100,7 @@ if [ "$OPTION_VERSION" = "latest" ]; then
91100
DDEV_VERSION="latest"
92101
DOCKER_TAGS=("-t $IMAGE_NAME:latest")
93102
elif [ "$OPTION_VERSION" = "stable" ]; then
94-
DDEV_VERSION="$(curl --silent -L -H "Accept: application/vnd.github+json" https://api.github.com/repos/ddev/ddev/releases/latest | jq -r '.tag_name')"
103+
DDEV_VERSION="$(github_api "repos/${GITHUB_OWNER}/ddev/releases/latest" | jq -r '.tag_name')"
95104

96105
if [[ ! "$DDEV_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
97106
echo "Error: Latest DDEV release '$DDEV_VERSION' is not a valid semver version."

‎tests/test.bats‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ setup() {
6868

6969
docker-run() {
7070
# Mount the shared volume to make bind mounts work
71-
docker run --rm -it \
71+
docker run --rm -it --pull never \
7272
--network ddev-docker \
7373
-e "DDEV_CI=true" \
7474
-e "DDEV_NO_INSTRUMENTATION=true" \

0 commit comments

Comments
 (0)