99 - cron : ' 0 0 * * *' # Runs daily at midnight
1010
1111 workflow_dispatch :
12+ inputs :
13+ dbsync_ref :
14+ description : ' cardano-db-sync tag or commit SHA to build (defaults to latest release)'
15+ required : false
16+ type : string
1217
1318permissions :
1419 contents : read
@@ -18,23 +23,52 @@ jobs:
1823 build :
1924 runs-on : ubuntu-latest
2025 outputs :
21- tag : ${{ steps.get_latest_tag.outputs.tag }}
26+ dbsync_ref : ${{ steps.resolve_dbsync_ref.outputs.dbsync_ref }}
27+ image_tag : ${{ steps.resolve_dbsync_ref.outputs.image_tag }}
2228 steps :
2329 - name : Checkout repository
2430 uses : actions/checkout@v4
2531
2632 - name : Set up Docker Buildx
2733 uses : docker/setup-buildx-action@v3
2834
29- - name : Get latest dbsync tag
30- id : get_latest_tag
35+ - name : Resolve dbsync ref
36+ id : resolve_dbsync_ref
37+ env :
38+ DBSYNC_REF_INPUT : ${{ github.event.inputs.dbsync_ref }}
3139 run : |
32- latest_tag=$(curl -s https://api.github.com/repos/intersectmbo/cardano-db-sync/releases/latest | jq -r .tag_name)
33- echo Target build tag: $latest_tag
34- if [[ -z "$latest_tag" || "$latest_tag" == "null" ]]; then
35- echo "Failed to get latest tag"; exit 1
40+ dbsync_ref=$(printf '%s' "$DBSYNC_REF_INPUT" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
41+
42+ if [[ -z "$dbsync_ref" ]]; then
43+ dbsync_ref=$(curl -fsSL https://api.github.com/repos/intersectmbo/cardano-db-sync/releases/latest | jq -r .tag_name)
44+ if [[ -z "$dbsync_ref" || "$dbsync_ref" == "null" ]]; then
45+ echo "Failed to get latest tag"; exit 1
46+ fi
47+ elif git ls-remote --exit-code --tags https://github.com/intersectmbo/cardano-db-sync.git "refs/tags/$dbsync_ref" >/dev/null 2>&1; then
48+ echo "Found cardano-db-sync tag: $dbsync_ref"
49+ else
50+ if [[ ! "$dbsync_ref" =~ ^[0-9a-fA-F]{7,40}$ ]]; then
51+ echo "dbsync_ref must be a cardano-db-sync tag or commit SHA: $dbsync_ref"
52+ exit 1
53+ fi
54+
55+ status_code=$(curl -s -o /tmp/dbsync-commit.json -w "%{http_code}" "https://api.github.com/repos/intersectmbo/cardano-db-sync/commits/$dbsync_ref")
56+ if [[ "$status_code" != "200" ]]; then
57+ echo "dbsync_ref must be a cardano-db-sync tag or commit SHA: $dbsync_ref"
58+ exit 1
59+ fi
3660 fi
37- echo "tag=$latest_tag" >> $GITHUB_OUTPUT
61+
62+ image_tag=$(printf '%s' "$dbsync_ref" | sed -E 's/[^A-Za-z0-9_.-]+/-/g; s/^[.-]+//; s/[.-]+$//')
63+ image_tag=${image_tag:0:128}
64+ if [[ -z "$image_tag" ]]; then
65+ echo "Unable to derive Docker image tag from dbsync ref: $dbsync_ref"; exit 1
66+ fi
67+
68+ echo "Target dbsync ref: $dbsync_ref"
69+ echo "Target image tag: $image_tag"
70+ echo "dbsync_ref=$dbsync_ref" >> $GITHUB_OUTPUT
71+ echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
3872
3973 - name : Log in to GitHub Container Registry
4074 uses : docker/login-action@v3
4983 context : .
5084 file : ./Dockerfile
5185 push : true
52- tags : ghcr.io/${{ github.repository_owner }}/cardano-db-sync:${{ steps.get_latest_tag .outputs.tag }}
86+ tags : ghcr.io/${{ github.repository_owner }}/cardano-db-sync:${{ steps.resolve_dbsync_ref .outputs.image_tag }}
5387 build-args : |
54- DBSYNC_TAG=${{ steps.get_latest_tag .outputs.tag }}
88+ DBSYNC_TAG=${{ steps.resolve_dbsync_ref .outputs.dbsync_ref }}
0 commit comments