2020-06-18 07:49:13 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-12-27 11:07:53 +00:00
|
|
|
|
|
|
|
set +u
|
|
|
|
|
2020-04-09 01:05:17 +00:00
|
|
|
if [[ $BUILDKITE_PULL_REQUEST != "false" ]]; then
|
2020-04-22 13:10:22 +00:00
|
|
|
if [[ $BUILDKITE_LABEL == ":service_dog: Linting" ]]; then
|
|
|
|
echo "--- :go::service_dog: Provide in-line commentary for pull request"
|
2020-04-09 01:05:17 +00:00
|
|
|
reviewdog -reporter=github-pr-review
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-07-02 06:56:45 +00:00
|
|
|
if [[ ! $BUILDKITE_BRANCH =~ ^(v.*) ]] && [[ $BUILDKITE_COMMAND_EXIT_STATUS == 0 ]]; then
|
2020-11-19 01:50:34 +00:00
|
|
|
if [[ $BUILDKITE_LABEL == ":hammer_and_wrench: Unit Test" ]] || [[ $BUILDKITE_LABEL =~ ":selenium:" ]]; then
|
2020-06-05 00:43:19 +00:00
|
|
|
echo "--- :codecov: Upload coverage reports"
|
2020-11-30 01:04:09 +00:00
|
|
|
if [[ $BUILDKITE_AGENT_META_DATA_CODECOV == "verbose" ]]; then
|
|
|
|
BUILDKITE_AGENT_META_DATA_CODECOV="-v"
|
|
|
|
fi
|
2021-01-16 10:25:02 +00:00
|
|
|
bash <(curl -s --connect-timeout 10 --retry 10 --retry-max-time 0 https://codecov.io/bash) -Z -c -s 'coverage*.txt' -F backend ${BUILDKITE_AGENT_META_DATA_CODECOV}
|
2020-11-30 10:12:46 +00:00
|
|
|
if [[ $BUILDKITE_LABEL =~ ":selenium:" ]]; then
|
|
|
|
cd web && yarn report
|
|
|
|
fi
|
|
|
|
bash <(curl -s --connect-timeout 10 --retry 10 --retry-max-time 0 https://codecov.io/bash) -Z -c -f '!*.go' -f '!*.zst' -F frontend ${BUILDKITE_AGENT_META_DATA_CODECOV}
|
2020-06-05 00:43:19 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-01-30 07:37:11 +00:00
|
|
|
if [[ $BUILDKITE_LABEL =~ ":selenium:" ]] || [[ $BUILDKITE_LABEL =~ ":docker: Build Image" ]]; then
|
2019-12-27 11:07:53 +00:00
|
|
|
CONTAINERS=$(docker ps -a -q)
|
2020-01-30 07:37:11 +00:00
|
|
|
if [[ ${CONTAINERS} != "" ]]; then
|
2020-03-19 05:15:54 +00:00
|
|
|
echo "--- :docker: Remove lingering containers"
|
2020-01-07 11:28:04 +00:00
|
|
|
docker rm -f ${CONTAINERS}
|
2019-12-27 11:07:53 +00:00
|
|
|
fi
|
2020-01-30 07:37:11 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-10 23:25:47 +00:00
|
|
|
if [[ $BUILDKITE_LABEL == ":docker: Image Deployments" ]]; then
|
|
|
|
cat .buildkite/annotations/artifacts | buildkite-agent annotate --style "success" --context "ctx-success"
|
|
|
|
fi
|
|
|
|
|
2020-02-01 08:10:18 +00:00
|
|
|
if [[ $BUILDKITE_LABEL =~ ":docker: Deploy" ]]; then
|
|
|
|
docker logout
|
2021-03-29 22:17:19 +00:00
|
|
|
docker logout ghcr.io
|
2020-02-01 08:10:18 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-05 12:24:19 +00:00
|
|
|
if [[ $BUILDKITE_LABEL == ":docker: Deploy Manifests" ]] && [[ $BUILDKITE_BRANCH == "master" ]] && [[ $BUILDKITE_PULL_REQUEST == "false" ]]; then
|
2020-02-03 09:07:01 +00:00
|
|
|
echo "--- :docker: Removing tags for deleted branches"
|
2020-02-05 12:24:19 +00: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)' | \
|
2020-05-06 03:28:44 +00:00
|
|
|
sed -r '/^(latest|master|develop|v.*|([[:digit:]]+)\.?([[:digit:]]+)?\.?([[:digit:]]+)?)|(amd64|arm32v7|arm64v8)$/d' | sort) && \
|
2020-02-03 09:07:01 +00: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
|
|
|
|
echo "Removing tag ${BRANCH_TAG}"
|
|
|
|
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-03-29 22:17:19 +00: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 | jq --arg tag ${BRANCH_TAG} '.[] | select(.metadata.container.tags[] | contains($tag)) | .id'); do
|
|
|
|
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/${GHCR_VERSION}
|
|
|
|
done
|
2020-02-03 09:07:01 +00:00
|
|
|
done
|
|
|
|
echo "--- :docker: Removing tags for merged or closed pull requests"
|
2020-05-06 03:28:44 +00: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"))' | \
|
|
|
|
sed -r '/(amd64|arm32v7|arm64v8)$/d' | sort) && \
|
2020-02-03 09:07:01 +00: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
|
|
|
|
echo "Removing tag ${PR_TAG}"
|
|
|
|
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-03-29 22:17:19 +00: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 | jq --arg tag ${PR_TAG} '.[] | select(.metadata.container.tags[] | contains($tag)) | .id'); do
|
|
|
|
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/${GHCR_VERSION}
|
|
|
|
done
|
|
|
|
done
|
|
|
|
echo "--- :docker: Removing empty tags for old images on GHCR"
|
|
|
|
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 | jq '.[] | select((.metadata.container.tags|length) == 0) | .id'); do
|
|
|
|
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/${GHCR_VERSION}
|
2020-02-03 09:07:01 +00:00
|
|
|
done
|
2020-03-10 23:25:47 +00:00
|
|
|
fi
|