-
-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (177 loc) · 6.74 KB
/
create-release.yml
File metadata and controls
204 lines (177 loc) · 6.74 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Create Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Type of release'
required: true
default: 'auto'
type: choice
options:
- auto
- major
- minor
- patch
dry_run:
description: 'Dry run (preview only)'
required: false
default: false
type: boolean
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.next_version.outputs.NEXT_VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Determine release type
id: release_type
run: |
if [ "${{ github.event.inputs.release_type }}" = "auto" ]; then
PREVIEW_OUTPUT=$(bundle exec rake release:preview)
echo "$PREVIEW_OUTPUT"
SUGGESTED_TYPE=$(echo "$PREVIEW_OUTPUT" | grep "Suggested release type:" | awk '{print $NF}')
if [ -z "$SUGGESTED_TYPE" ]; then
echo "Could not determine release type automatically, defaulting to patch"
RELEASE_TYPE="patch"
else
RELEASE_TYPE="$SUGGESTED_TYPE"
fi
else
RELEASE_TYPE="${{ github.event.inputs.release_type }}"
fi
echo "RELEASE_TYPE=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "Selected release type: $RELEASE_TYPE"
- name: Get current version
id: current_version
run: |
CURRENT=$(ruby scripts/version.rb current)
echo "CURRENT_VERSION=$CURRENT" >> $GITHUB_OUTPUT
- name: Calculate next version
id: next_version
run: |
RELEASE_TYPE=${{ steps.release_type.outputs.RELEASE_TYPE }}
NEXT_VERSION=$(ruby scripts/version.rb next "$RELEASE_TYPE")
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "Next version will be: $NEXT_VERSION"
- name: Preview release (dry run)
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "=== DRY RUN MODE ==="
echo "Current version: ${{ steps.current_version.outputs.CURRENT_VERSION }}"
echo "Release type: ${{ steps.release_type.outputs.RELEASE_TYPE }}"
echo "Next version: ${{ steps.next_version.outputs.NEXT_VERSION }}"
echo
echo "=== COMMIT PREVIEW ==="
bundle exec rake release:preview
echo
echo "=== CHANGELOG PREVIEW ==="
bundle exec rake release:changelog[${{ steps.next_version.outputs.NEXT_VERSION }}] || true
- name: Run tests before release
if: ${{ github.event.inputs.dry_run != 'true' }}
run: bundle exec rake ci
- name: Generate changelog
if: ${{ github.event.inputs.dry_run != 'true' }}
id: changelog
run: |
VERSION="${{ steps.next_version.outputs.NEXT_VERSION }}"
bundle exec ruby -e "
require_relative 'lib/version_helper'
puts VersionHelper.generate_changelog_for_version('$VERSION')
" > changelog_body.txt
{
echo 'BODY<<EOF'
cat changelog_body.txt
echo 'EOF'
} >> $GITHUB_OUTPUT
echo "Generated changelog:"
cat changelog_body.txt
- name: Create tag
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}"
echo "Creating tag $VERSION_TAG..."
git tag -a "$VERSION_TAG" -m "Release version ${{ steps.next_version.outputs.NEXT_VERSION }}"
git push origin "$VERSION_TAG"
echo "Tag $VERSION_TAG pushed."
- name: Build and package application
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
ARCHIVE="slack-github-threads-v${{ steps.next_version.outputs.NEXT_VERSION }}.tar.gz"
tar -czf "/tmp/$ARCHIVE" \
--exclude='.git*' \
--exclude='test/' \
--exclude='log/*.log' \
--exclude='.env*' \
--exclude='tmp/' \
.
mv "/tmp/$ARCHIVE" .
- name: Create GitHub Release
if: ${{ github.event.inputs.dry_run != 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.next_version.outputs.NEXT_VERSION }}
name: Release v${{ steps.next_version.outputs.NEXT_VERSION }}
body: ${{ steps.changelog.outputs.BODY }}
files: slack-github-threads-v${{ steps.next_version.outputs.NEXT_VERSION }}.tar.gz
draft: false
prerelease: false
- name: Output summary
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
echo "## Release Created! 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **Type**: ${{ steps.release_type.outputs.RELEASE_TYPE }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY
- name: Output dry run summary
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "## Dry Run Complete! 👀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Would create version**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **Release type**: ${{ steps.release_type.outputs.RELEASE_TYPE }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To create the actual release, run this workflow again without dry run mode." >> $GITHUB_STEP_SUMMARY
docker:
runs-on: ubuntu-latest
needs: release
if: ${{ github.event.inputs.dry_run != 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ needs.release.outputs.version }}
ghcr.io/${{ github.repository }}:latest
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.version=${{ needs.release.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}