All checks were successful
Build and deploy Flutter Web / build (push) Successful in 6m57s
69 lines
2.3 KiB
YAML
69 lines
2.3 KiB
YAML
name: Build and deploy Flutter Web
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: builder
|
|
env:
|
|
SERVICE_NAME: flutter
|
|
IMAGE_SHA: gitea.dsrptlab.com/mapflow/flutter:${{ github.sha }}
|
|
IMAGE_LATEST: gitea.dsrptlab.com/mapflow/flutter:latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Configure Gitea registry auth
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p ~/.docker
|
|
auth="$(printf '%s:%s' "${{ secrets.REGISTRY_USERNAME }}" "${{ secrets.REGISTRY_TOKEN }}" | base64 | tr -d '\n')"
|
|
printf '{"auths":{"gitea.dsrptlab.com":{"auth":"%s"}}}\n' "$auth" > ~/.docker/config.json
|
|
|
|
- name: Build and push image
|
|
run: |
|
|
set -euo pipefail
|
|
for attempt in 1 2 3; do
|
|
if docker buildx build \
|
|
--push \
|
|
--provenance=false \
|
|
--tag "$IMAGE_SHA" \
|
|
--tag "$IMAGE_LATEST" \
|
|
--build-arg MAPBOX_ACCESS_TOKEN="${{ secrets.MAPBOX_ACCESS_TOKEN }}" \
|
|
--build-arg MAPBOX_STYLE="mapbox/streets-v12" \
|
|
--build-arg TELEGRAM_BOT_USERNAME="carfteebot" \
|
|
.; then
|
|
exit 0
|
|
fi
|
|
sleep "$((attempt * 10))"
|
|
done
|
|
exit 1
|
|
|
|
- name: Skip stale deployment
|
|
run: |
|
|
set -euo pipefail
|
|
latest_sha="$(git ls-remote origin refs/heads/main | awk '{print $1}')"
|
|
if [ "$latest_sha" = "${GITHUB_SHA}" ]; then
|
|
touch .deploy-current
|
|
else
|
|
echo "A newer main commit exists: $latest_sha. Skipping deploy for ${GITHUB_SHA}."
|
|
fi
|
|
|
|
- name: Trigger Dokploy deploy webhook
|
|
run: |
|
|
set -euo pipefail
|
|
[ -f .deploy-current ] || exit 0
|
|
payload=$(cat <<JSON
|
|
{"ref":"refs/heads/main","after":"$GITHUB_SHA","commits":[{"id":"$GITHUB_SHA","message":"$SERVICE_NAME #${GITHUB_RUN_NUMBER:-0} ${GITHUB_SHA:0:7}","modified":["Dockerfile"]}]}
|
|
JSON
|
|
)
|
|
response_file="$(mktemp)"
|
|
status_code="$(curl -sS -o "$response_file" -w "%{http_code}" -X POST "${{ secrets.DOKPLOY_DEPLOY_WEBHOOK }}" \
|
|
-H "x-gitea-event: push" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload")"
|
|
cat "$response_file"
|
|
[ "$status_code" = "200" ]
|