-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (155 loc) · 6.55 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: build
on:
workflow_dispatch:
pull_request:
paths:
- '25.2/**'
- '26.2/**'
- '27.1/**'
- '28.0rc1/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: ${{ github.event_name == 'pull_request' && 8 || 1 }}
matrix:
version:
- '25.2/alpine'
- '25.2'
- '26.2/alpine'
- '26.2'
- '27.1/alpine'
- '27.1'
- '28.0rc1/alpine'
- '28.0rc1'
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Prepare Docker build
id: prepare
run: |
BITCOIN_VERSION=${{matrix.version}}
echo "Processing: $BITCOIN_VERSION"
# Check if the version ends with /alpine
if [[ $BITCOIN_VERSION == */alpine ]]; then
ALPINE=true
BITCOIN_VERSION=${BITCOIN_VERSION%/alpine}
else
ALPINE=false
fi
# Check if the version contains rc*
if [[ $BITCOIN_VERSION == *rc* ]]; then
RC=$(echo "$BITCOIN_VERSION" | grep -oP 'rc\d+')
BITCOIN_VERSION=${BITCOIN_VERSION%rc*}
else
RC=""
fi
LATEST_BITCOIN_MAJOR_VERSION=$(find . -maxdepth 1 -type d -not -path '*/\.*' -not -path '*/deprecated' -not -name '*rc*' -not -name 'master' | sort -V | tail -n 1 | cut -c 3- )
PLATFORMS="linux/amd64"
PUSH=false
REPO=bitcoin/bitcoin
TAGS=()
# Split the extracted version into major, minor and patch variables
IFS='.' read -r MAJOR MINOR PATCH <<< "$BITCOIN_VERSION"
# Output the extracted version parts
echo "Major Version: $MAJOR"
echo "Minor Version: $MINOR"
echo "Patch Version: ${PATCH:-0}"
echo "RC: $RC"
echo "Latest major version: $LATEST_BITCOIN_MAJOR_VERSION"
# Add primary tags
if ! $ALPINE; then
# Non-alpine
if [[ -n "$RC" ]]; then
if [[ -n "$PATCH" && "$PATCH" -ne 0 ]]; then
TAGS+=("$REPO:${MAJOR}.${MINOR}.${PATCH}${RC}")
else
TAGS+=("$REPO:${MAJOR}.${MINOR}${RC}")
fi
elif [[ -n "$PATCH" && "$PATCH" -ne 0 ]]; then
TAGS+=("$REPO:${MAJOR}.${MINOR}.${PATCH}")
TAGS+=("$REPO:${MAJOR}")
else
TAGS+=("$REPO:${MAJOR}.${MINOR}")
TAGS+=("$REPO:${MAJOR}")
fi
else
# Alpine
if [[ -n "$RC" ]]; then
if [[ -n "$PATCH" && "$PATCH" -ne 0 ]]; then
TAGS+=("$REPO:${MAJOR}.${MINOR}.${PATCH}${RC}-alpine")
else
TAGS+=("$REPO:${MAJOR}.${MINOR}${RC}-alpine")
fi
elif [[ -n "$PATCH" && "$PATCH" -ne 0 ]]; then
TAGS+=("$REPO:${MAJOR}.${MINOR}.${PATCH}-alpine")
TAGS+=("$REPO:${MAJOR}-alpine")
else
TAGS+=("$REPO:${MAJOR}.${MINOR}-alpine")
TAGS+=("$REPO:${MAJOR}-alpine")
fi
fi
# Create the stripped version including patch if it exists
if [[ -n "$PATCH" && "$PATCH" -ne 0 ]]; then
STRIPPED_VERSION="$MAJOR.$MINOR.$PATCH"
else
STRIPPED_VERSION="$MAJOR.$MINOR"
fi
echo "Stripped version: $STRIPPED_VERSION"
# Add any "latest" tags if not a release candidate
LATEST_MAJOR=$(echo "$LATEST_BITCOIN_MAJOR_VERSION" | awk -F. '{print $1}')
LATEST_MINOR=$(echo "$LATEST_BITCOIN_MAJOR_VERSION" | awk -F. '{print $2}')
LATEST_PATCH=$(echo "$LATEST_BITCOIN_MAJOR_VERSION" | awk -F. '{print $3}')
if [[ -z "$RC" && ("$MAJOR" -gt "$LATEST_MAJOR" || ("$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -gt "$LATEST_MINOR") || ("$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq "$LATEST_MINOR" && "${PATCH:-0}" -ge "${LATEST_PATCH:-0}")) ]]; then
if ! $ALPINE; then
echo "Version ${MAJOR}.${MINOR}.${PATCH} >= ${LATEST_BITCOIN_MAJOR_VERSION}, tagging as 'latest'"
TAGS+=("$REPO:latest")
TAGS+=("$REPO:${MAJOR}")
else
echo "Version ${MAJOR}.${MINOR}.${PATCH} >= ${LATEST_BITCOIN_MAJOR_VERSION}, tagging as 'alpine'"
TAGS+=("$REPO:alpine")
TAGS+=("$REPO:${MAJOR}-alpine")
fi
fi
if [[ $GITHUB_REF == "refs/heads/master" ]]; then
PUSH=true
fi
if ! $ALPINE; then
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
fi
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | tee -a $GITHUB_OUTPUT
echo "docker_platforms=${PLATFORMS}" | tee -a $GITHUB_OUTPUT
echo "docker_username=bitcoin" | tee -a $GITHUB_OUTPUT
echo "push=${PUSH}" | tee -a $GITHUB_OUTPUT
echo "tags=${TAGS[@]}" | tee -a $GITHUB_OUTPUT
- name: Login into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ steps.prepare.outputs.docker_username }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build Docker image
run: |
TAGS=(${{ steps.prepare.outputs.tags }})
echo "Build date: ${{ steps.prepare.outputs.build_date }}"
echo "Docker platform: ${{ steps.prepare.outputs.docker_platforms }}"
echo "Push: ${{ steps.prepare.outputs.push }}"
echo "Tags: ${{ steps.prepare.outputs.tags }}"
echo docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/