-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (93 loc) · 3.86 KB
/
release.yml
File metadata and controls
107 lines (93 loc) · 3.86 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
name: Release
on:
pull_request:
types: [closed]
branches:
- main
- master
concurrency:
group: release-${{ github.event.pull_request.base.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
release:
name: 🚀 Release
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.base.ref }}
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1.0"
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Skip when PR is already released
id: already_released
run: |
if git log --oneline --grep="(pr #${{ github.event.pull_request.number }})" -n 1 | grep -q "chore(release):"; then
echo "value=true" >> "$GITHUB_OUTPUT"
else
echo "value=false" >> "$GITHUB_OUTPUT"
fi
- name: Determine and apply version bump
id: release_meta
if: steps.already_released.outputs.value != 'true'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
PR_BODY_FILE=$(mktemp)
printf '%s' "$PR_BODY" > "$PR_BODY_FILE"
ruby scripts/release/bump_version.rb \
--title "$PR_TITLE" \
--body-file "$PR_BODY_FILE" \
--output "$GITHUB_OUTPUT"
- name: Stop when PR does not require release
if: steps.already_released.outputs.value == 'true' || steps.release_meta.outputs.should_release != 'true'
run: |
if [ "${{ steps.already_released.outputs.value }}" = "true" ]; then
echo "PR #${{ github.event.pull_request.number }} is already released; skipping."
exit 0
fi
echo "No release type found in PR title; skipping."
exit 0
- name: Commit version files
if: steps.already_released.outputs.value != 'true' && steps.release_meta.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add lib/getstream_ruby/version.rb
if git diff --cached --quiet; then
echo "No version changes to commit."
exit 0
fi
git commit -m "chore(release): v${{ steps.release_meta.outputs.version }} (pr #${{ github.event.pull_request.number }})"
git push origin "HEAD:${{ github.event.pull_request.base.ref }}"
- name: Create release tag
if: steps.already_released.outputs.value != 'true' && steps.release_meta.outputs.should_release == 'true'
run: |
git tag "${{ steps.release_meta.outputs.tag }}"
git push origin "${{ steps.release_meta.outputs.tag }}"
- name: Build and publish gem
if: steps.already_released.outputs.value != 'true' && steps.release_meta.outputs.should_release == 'true'
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
gem build getstream-ruby.gemspec
gem push getstream-ruby-${{ steps.release_meta.outputs.version }}.gem --key "$GEM_HOST_API_KEY"
- name: Create release on GitHub
if: steps.already_released.outputs.value != 'true' && steps.release_meta.outputs.should_release == 'true'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.release_meta.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Release v${{ steps.release_meta.outputs.version }}
- Bump type: `${{ steps.release_meta.outputs.bump }}`
- Previous: `${{ steps.release_meta.outputs.previous_version }}`
- Next: `${{ steps.release_meta.outputs.version }}`