|
44 | 44 | echo "IMAGE=${REGISTRY}/${OWNER}/${IMAGE_NAME}" >> "$GITHUB_ENV" |
45 | 45 | echo "Image namespace: ${REGISTRY}/${OWNER}/${IMAGE_NAME}" |
46 | 46 |
|
| 47 | + - name: Compute build info |
| 48 | + id: build_info |
| 49 | + run: | |
| 50 | + { |
| 51 | + echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 52 | + echo "source=https://github.com/${GITHUB_REPOSITORY}" |
| 53 | + echo "branch=${GITHUB_REF_NAME}" |
| 54 | + echo "run_url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" |
| 55 | + echo "author<<EOF" |
| 56 | + git log -1 --format='%an <%ae>' |
| 57 | + echo "EOF" |
| 58 | + } >> "$GITHUB_OUTPUT" |
| 59 | +
|
47 | 60 | - name: Docker metadata |
48 | 61 | id: meta |
49 | 62 | uses: docker/metadata-action@v6 |
|
68 | 81 | ${{ env.IMAGE }}:ci |
69 | 82 | ${{ steps.meta.outputs.tags }} |
70 | 83 | labels: ${{ steps.meta.outputs.labels }} |
| 84 | + build-args: | |
| 85 | + BUILD_DATE=${{ steps.build_info.outputs.created }} |
| 86 | + VCS_REF=${{ github.sha }} |
| 87 | + VCS_URL=${{ steps.build_info.outputs.source }} |
| 88 | + SOURCE_BRANCH=${{ steps.build_info.outputs.branch }} |
| 89 | + IMAGE_NAME=${{ env.IMAGE }} |
| 90 | + GITHUB_RUN_ID=${{ github.run_id }} |
| 91 | + GITHUB_RUN_ATTEMPT=${{ github.run_attempt }} |
| 92 | + GITHUB_RUN_URL=${{ steps.build_info.outputs.run_url }} |
| 93 | + GITHUB_ACTOR=${{ github.actor }} |
| 94 | + COMMIT_AUTHOR=${{ steps.build_info.outputs.author }} |
71 | 95 | cache-from: type=gha |
72 | 96 | cache-to: type=gha,mode=max,ignore-error=true |
73 | 97 |
|
@@ -124,6 +148,19 @@ jobs: |
124 | 148 | echo "IMAGE=${REGISTRY}/${OWNER}/${IMAGE_NAME}" >> "$GITHUB_ENV" |
125 | 149 | echo "Image namespace: ${REGISTRY}/${OWNER}/${IMAGE_NAME}" |
126 | 150 |
|
| 151 | + - name: Compute build info |
| 152 | + id: build_info |
| 153 | + run: | |
| 154 | + { |
| 155 | + echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 156 | + echo "source=https://github.com/${GITHUB_REPOSITORY}" |
| 157 | + echo "branch=${GITHUB_REF_NAME}" |
| 158 | + echo "run_url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" |
| 159 | + echo "author<<EOF" |
| 160 | + git log -1 --format='%an <%ae>' |
| 161 | + echo "EOF" |
| 162 | + } >> "$GITHUB_OUTPUT" |
| 163 | +
|
127 | 164 | - name: Docker metadata |
128 | 165 | id: meta |
129 | 166 | uses: docker/metadata-action@v6 |
@@ -165,5 +202,67 @@ jobs: |
165 | 202 | push: true |
166 | 203 | tags: ${{ steps.meta.outputs.tags }} |
167 | 204 | labels: ${{ steps.meta.outputs.labels }} |
| 205 | + build-args: | |
| 206 | + BUILD_DATE=${{ steps.build_info.outputs.created }} |
| 207 | + VCS_REF=${{ github.sha }} |
| 208 | + VCS_URL=${{ steps.build_info.outputs.source }} |
| 209 | + SOURCE_BRANCH=${{ steps.build_info.outputs.branch }} |
| 210 | + IMAGE_NAME=${{ env.IMAGE }} |
| 211 | + GITHUB_RUN_ID=${{ github.run_id }} |
| 212 | + GITHUB_RUN_ATTEMPT=${{ github.run_attempt }} |
| 213 | + GITHUB_RUN_URL=${{ steps.build_info.outputs.run_url }} |
| 214 | + GITHUB_ACTOR=${{ github.actor }} |
| 215 | + COMMIT_AUTHOR=${{ steps.build_info.outputs.author }} |
168 | 216 | cache-from: type=gha |
169 | 217 | cache-to: type=gha,mode=max,ignore-error=true |
| 218 | +
|
| 219 | + update-size-badge: |
| 220 | + needs: build |
| 221 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 222 | + runs-on: ubuntu-latest |
| 223 | + continue-on-error: true |
| 224 | + permissions: |
| 225 | + contents: write |
| 226 | +
|
| 227 | + steps: |
| 228 | + - name: Configure Git default branch |
| 229 | + run: git config --global init.defaultBranch master |
| 230 | +
|
| 231 | + - name: Checkout |
| 232 | + uses: actions/checkout@v6 |
| 233 | + with: |
| 234 | + fetch-depth: 0 |
| 235 | +
|
| 236 | + - name: Generate badge data |
| 237 | + run: BADGE_PATH=tmp/master-payload-size.json bash scripts/update-size-badge.sh |
| 238 | +
|
| 239 | + - name: Publish badge data |
| 240 | + run: | |
| 241 | + set -euo pipefail |
| 242 | + badge_branch="size-badge-data" |
| 243 | + badge_file="tmp/master-payload-size.json" |
| 244 | + worktree="$(mktemp -d)" |
| 245 | +
|
| 246 | + git config user.name "github-actions[bot]" |
| 247 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 248 | +
|
| 249 | + if git ls-remote --exit-code --heads origin "$badge_branch" >/dev/null 2>&1; then |
| 250 | + git fetch origin "$badge_branch" |
| 251 | + git worktree add "$worktree" "origin/$badge_branch" |
| 252 | + git -C "$worktree" switch -c "$badge_branch" |
| 253 | + else |
| 254 | + git worktree add --detach "$worktree" |
| 255 | + git -C "$worktree" switch --orphan "$badge_branch" |
| 256 | + git -C "$worktree" rm -rf . >/dev/null 2>&1 || true |
| 257 | + fi |
| 258 | +
|
| 259 | + cp "$badge_file" "$worktree/master-payload-size.json" |
| 260 | + git -C "$worktree" add master-payload-size.json |
| 261 | +
|
| 262 | + if git -C "$worktree" diff --cached --quiet; then |
| 263 | + echo "Badge data unchanged" |
| 264 | + exit 0 |
| 265 | + fi |
| 266 | +
|
| 267 | + git -C "$worktree" commit -m "Update master payload badge" |
| 268 | + git -C "$worktree" push origin "HEAD:$badge_branch" |
0 commit comments