2020-06-18 14:49:13 +07:00
|
|
|
#!/usr/bin/env bash
|
2019-12-27 18:07:53 +07:00
|
|
|
|
|
|
|
set +u
|
|
|
|
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]]; then
|
|
|
|
if [[ "${BUILDKITE_LABEL}" == ":service_dog: Linting" ]]; then
|
2020-04-22 20:10:22 +07:00
|
|
|
echo "--- :go::service_dog: Provide in-line commentary for pull request"
|
2020-04-09 08:05:17 +07:00
|
|
|
reviewdog -reporter=github-pr-review
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ ! "${BUILDKITE_BRANCH}" =~ ^(v.*) ]] && [[ "${BUILDKITE_COMMAND_EXIT_STATUS}" == 0 ]]; then
|
|
|
|
if [[ "${BUILDKITE_LABEL}" == ":hammer_and_wrench: Unit Test" ]] || [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then
|
2020-06-05 07:43:19 +07:00
|
|
|
echo "--- :codecov: Upload coverage reports"
|
2021-10-08 07:17:08 +07:00
|
|
|
NAME="UnitTest"
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ "${BUILDKITE_AGENT_META_DATA_CODECOV}" == "verbose" ]]; then
|
2020-11-30 08:04:09 +07:00
|
|
|
BUILDKITE_AGENT_META_DATA_CODECOV="-v"
|
|
|
|
fi
|
2021-10-08 07:17:08 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then
|
|
|
|
NAME=$(echo ${BUILDKITE_LABEL/:selenium: /} | awk '{ print $1 }')
|
|
|
|
fi
|
|
|
|
codecov -Z -c -f 'coverage*.txt' -n ${NAME} -F backend "${BUILDKITE_AGENT_META_DATA_CODECOV}"
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then
|
2021-09-29 14:24:21 +07:00
|
|
|
cd web && pnpm report
|
2020-11-30 17:12:46 +07:00
|
|
|
fi
|
2021-10-08 07:17:08 +07:00
|
|
|
codecov -Z -c -f '!Dockerfile*' -f '!*.go' -f '!*.zst' -n ${NAME} -F frontend "${BUILDKITE_AGENT_META_DATA_CODECOV}"
|
2020-06-05 07:43:19 +07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]] || [[ "${BUILDKITE_LABEL}" =~ ":docker: Build Image" ]]; then
|
2019-12-27 18:07:53 +07:00
|
|
|
CONTAINERS=$(docker ps -a -q)
|
2020-01-30 14:37:11 +07:00
|
|
|
if [[ ${CONTAINERS} != "" ]]; then
|
2020-03-19 12:15:54 +07:00
|
|
|
echo "--- :docker: Remove lingering containers"
|
2020-01-07 18:28:04 +07:00
|
|
|
docker rm -f ${CONTAINERS}
|
2019-12-27 18:07:53 +07:00
|
|
|
fi
|
2020-01-30 14:37:11 +07:00
|
|
|
fi
|
|
|
|
|
2021-09-16 19:39:18 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" == ":debian: Package Builds" ]]; then
|
2020-03-11 06:25:47 +07:00
|
|
|
cat .buildkite/annotations/artifacts | buildkite-agent annotate --style "success" --context "ctx-success"
|
|
|
|
fi
|
|
|
|
|
2021-06-26 08:45:21 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" =~ ":docker: Deploy" ]]; then
|
2020-02-01 15:10:18 +07:00
|
|
|
docker logout
|
2021-03-30 05:17:19 +07:00
|
|
|
docker logout ghcr.io
|
2020-02-01 15:10:18 +07:00
|
|
|
fi
|
|
|
|
|
2021-09-16 19:39:18 +07:00
|
|
|
if [[ "${BUILDKITE_LABEL}" == ":docker: Deploy Manifest" ]] && [[ "${BUILDKITE_BRANCH}" == "master" ]] && [[ "${BUILDKITE_PULL_REQUEST}" == "false" ]]; then
|
2020-02-03 16:07:01 +07:00
|
|
|
echo "--- :docker: Removing tags for deleted branches"
|
2020-02-05 19:24:19 +07:00
|
|
|
anontoken=$(curl -fsL --retry 3 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:authelia/authelia:pull' | jq -r .token)
|
|
|
|
authtoken=$(curl -fs --retry 3 -H "Content-Type: application/json" -X "POST" -d '{"username": "'${DOCKER_USERNAME}'", "password": "'${DOCKER_PASSWORD}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
|
|
|
|
for BRANCH_TAG in $(dockerbranchtags=$(curl -fsL --retry 3 -H "Authorization: Bearer ${anontoken}" https://registry-1.docker.io/v2/authelia/authelia/tags/list | jq -r '.tags[] | select(startswith("PR") | not)' | \
|
2021-09-18 12:48:23 +07:00
|
|
|
sed -r '/^(latest|master|develop|v.*|([[:digit:]]+)\.?([[:digit:]]+)?\.?([[:digit:]]+)?)$/d' | sort) && \
|
2020-02-03 16:07:01 +07:00
|
|
|
githubbranches=$(curl -fs --retry 3 https://api.github.com/repos/authelia/authelia/branches | jq -r '.[].name' | sort) && \
|
|
|
|
comm -23 <(echo "${dockerbranchtags}") <(echo "${githubbranches}")); do
|
2021-09-18 12:48:23 +07:00
|
|
|
echo "Removing tag ${BRANCH_TAG} from docker.io"
|
2020-02-03 16:07:01 +07:00
|
|
|
curl -fsL --retry 3 -o /dev/null -X "DELETE" -H "Authorization: JWT ${authtoken}" https://hub.docker.com/v2/repositories/authelia/authelia/tags/${BRANCH_TAG}/
|
2021-09-17 21:15:43 +07:00
|
|
|
for i in {1..5}; do
|
2021-09-18 15:09:19 +07:00
|
|
|
for GHCR_VERSION in $(curl -fsL --retry 3 -H "Authorization: Bearer ${GHCR_PASSWORD}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/orgs/authelia/packages/container/authelia/versions?page=${i}&per_page=100" | jq -j --arg tag ${BRANCH_TAG} '.[] | select(.metadata.container.tags[] | contains($tag)) | .metadata.container.tags[], ",", .id, "\n"'); do
|
2021-09-18 12:48:23 +07:00
|
|
|
IFS=','
|
|
|
|
read -a TAGID <<< ${GHCR_VERSION}
|
|
|
|
echo "Removing tag ${TAGID[0]} with id ${TAGID[1]} from ghcr.io"
|
|
|
|
curl -fsL --retry 3 -o /dev/null -X "DELETE" -H "Authorization: Bearer ${GHCR_PASSWORD}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/orgs/authelia/packages/container/authelia/versions/${TAGID[1]}
|
2021-09-17 21:15:43 +07:00
|
|
|
done
|
2021-03-30 05:17:19 +07:00
|
|
|
done
|
2020-02-03 16:07:01 +07:00
|
|
|
done
|
|
|
|
echo "--- :docker: Removing tags for merged or closed pull requests"
|
2021-09-18 12:48:23 +07:00
|
|
|
for PR_TAG in $(dockerprtags=$(curl -fsL --retry 3 -H "Authorization: Bearer ${anontoken}" https://registry-1.docker.io/v2/authelia/authelia/tags/list | jq -r '.tags[] | select(startswith("PR"))' | sort) && \
|
2020-02-03 16:07:01 +07:00
|
|
|
githubprs=$(curl -fs --retry 3 https://api.github.com/repos/authelia/authelia/pulls | jq -r '.[].number' | sed -e 's/^/PR/' | sort) && \
|
|
|
|
comm -23 <(echo "${dockerprtags}") <(echo "${githubprs}")); do
|
2021-09-18 12:48:23 +07:00
|
|
|
echo "Removing tag ${PR_TAG} from docker.io"
|
2020-02-03 16:07:01 +07:00
|
|
|
curl -fsL --retry 3 -o /dev/null -X "DELETE" -H "Authorization: JWT ${authtoken}" https://hub.docker.com/v2/repositories/authelia/authelia/tags/${PR_TAG}/
|
2021-09-17 21:15:43 +07:00
|
|
|
for i in {1..5}; do
|
2021-09-18 15:09:19 +07:00
|
|
|
for GHCR_VERSION in $(curl -fsL --retry 3 -H "Authorization: Bearer ${GHCR_PASSWORD}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/orgs/authelia/packages/container/authelia/versions?page=${i}&per_page=100" | jq -j --arg tag ${PR_TAG} '.[] | select(.metadata.container.tags[] | contains($tag)) | .metadata.container.tags[], ",", .id, "\n"'); do
|
2021-09-18 12:48:23 +07:00
|
|
|
IFS=','
|
|
|
|
read -a TAGID <<< ${GHCR_VERSION}
|
|
|
|
echo "Removing tag ${TAGID[0]} with id ${TAGID[1]} from ghcr.io"
|
|
|
|
curl -fsL --retry 3 -o /dev/null -X "DELETE" -H "Authorization: Bearer ${GHCR_PASSWORD}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/orgs/authelia/packages/container/authelia/versions/${TAGID[1]}
|
2021-09-17 21:15:43 +07:00
|
|
|
done
|
2021-03-30 05:17:19 +07:00
|
|
|
done
|
|
|
|
done
|
2021-09-14 17:29:23 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${BUILDKITE_LABEL}" == ":github: Deploy Artifacts" ]]; then
|
|
|
|
echo "--- :go: Force module index update"
|
2021-09-17 17:59:41 +07:00
|
|
|
rm go.mod go.sum
|
2021-09-14 17:29:23 +07:00
|
|
|
go get github.com/authelia/authelia/v4
|
2020-03-11 06:25:47 +07:00
|
|
|
fi
|