forked from supabase/etl
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (145 loc) · 4.91 KB
/
release.yml
File metadata and controls
155 lines (145 loc) · 4.91 KB
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
name: Release
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 1.2.3)"
type: string
required: true
permissions:
contents: write
actions: write
jobs:
version:
name: Determine Version
runs-on: blacksmith-2vcpu-ubuntu-2404
# Gate: manual dispatch OR merged PRs labeled 'release'.
if: |
github.event_name == 'workflow_dispatch' || (
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release')
)
outputs:
tag: ${{ steps.ver.outputs.tag }}
version: ${{ steps.ver.outputs.version }}
is_pr_merge: ${{ steps.ver.outputs.is_pr_merge }}
steps:
- name: Extract Tag and Version
id: ver
shell: bash
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
RAW="${{ inputs.version }}"
TAG="v${RAW#v}"
PR_MERGE=false
else
# pull_request closed event (merged into main)
HEAD_REF="${{ github.event.pull_request.head.ref }}"
if [[ "$HEAD_REF" =~ ^release/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
RAW="${BASH_REMATCH[1]}"
else
echo "Failed to extract version from PR branch name: $HEAD_REF (expected release/vX.Y.Z)" >&2
exit 1
fi
TAG="v${RAW}"
PR_MERGE="${{ github.event.pull_request.merged }}"
fi
CLEANED="${RAW#v}"
if [[ ! "$CLEANED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version: $CLEANED" >&2
exit 1
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${CLEANED}" >> "$GITHUB_OUTPUT"
echo "is_pr_merge=${PR_MERGE}" >> "$GITHUB_OUTPUT"
create-tag:
name: Create Tag
needs: version
if: needs.version.outputs.is_pr_merge == 'true' || github.event_name == 'workflow_dispatch'
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
contents: write
steps:
- name: Checkout merge commit (PR merge)
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Checkout main (manual dispatch)
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4
- name: Create and Push Tag
shell: bash
env:
TAG: ${{ needs.version.outputs.tag }}
run: |
set -euo pipefail
git fetch --tags
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists; skipping creation."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
build-and-push:
name: Build and Push Docker Images
needs: [version, create-tag]
strategy:
matrix:
image: [etl-api, etl-replicator]
uses: ./.github/workflows/docker-build.yml
with:
image: docker.io/${{ vars.DOCKERHUB_USERNAME }}/${{ matrix.image }}
context: .
file: ./${{ matrix.image }}/Dockerfile
push: true
tag_with_version: true
version: ${{ needs.version.outputs.version }}
checkout_ref: refs/tags/${{ needs.version.outputs.tag }}
secrets: inherit
github-release:
name: Create GitHub Release
needs: [version, create-tag, build-and-push]
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Generate Release Notes
id: notes
shell: bash
run: |
set -euo pipefail
USER="${{ vars.DOCKERHUB_USERNAME }}"
TAG="${{ needs.version.outputs.tag }}"
{
echo "body<<MARKER"
echo "Release ${TAG}"
echo
echo "Docker images published:"
echo "- docker.io/${USER}/etl-api:latest"
echo "- docker.io/${USER}/etl-api:${TAG}"
echo "- docker.io/${USER}/etl-replicator:latest"
echo "- docker.io/${USER}/etl-replicator:${TAG}"
echo
echo "View on Docker Hub:"
echo "- https://hub.docker.com/r/${USER}/etl-api"
echo "- https://hub.docker.com/r/${USER}/etl-replicator"
echo "MARKER"
} >> "$GITHUB_OUTPUT"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.tag }}
name: Release ${{ needs.version.outputs.tag }}
body: ${{ steps.notes.outputs.body }}
draft: false
prerelease: false