-
Notifications
You must be signed in to change notification settings - Fork 18
109 lines (97 loc) · 4.57 KB
/
Copy pathrelease.yml
File metadata and controls
109 lines (97 loc) · 4.57 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
---
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 1.12.0)"
required: true
type: string
jobs:
release:
name: Release v${{ github.event.inputs.version }}
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-ruby-and-dependencies
with:
ruby-version: "4.0"
cache-apt-packages: true
- name: Verify version
id: verify
run: |
GEM_VERSION="${{ github.event.inputs.version }}"
CODE_VERSION=$(ruby -I lib -r capybara/screenshot/diff/version -e "puts Capybara::Screenshot::Diff::VERSION")
if [ "$GEM_VERSION" != "$CODE_VERSION" ]; then
echo "Version mismatch: input=$GEM_VERSION code=$CODE_VERSION"
exit 1
fi
# Decide Pre-release here rather than letting the release action infer
# it: v2.0.0.beta4 was published as a FULL release and took the Latest
# badge off 1.15.1, while beta1-3 came out correctly under the SAME
# action version -- so the inference is unreliable, not merely absent.
# Gem::Version is the authority that already decides whether `~> 2.0`
# resolves this version, so the badge and the resolver cannot disagree.
PRERELEASE=$(ruby -rrubygems -e 'print Gem::Version.new(ARGV[0]).prerelease?' "$GEM_VERSION")
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
echo "Releasing $GEM_VERSION (prerelease=$PRERELEASE)"
- name: Test
run: bundle exec rake test:unit
# Idempotent so a failed run can be re-dispatched (bit us at beta1):
# skip when the tag already exists at HEAD, fail loudly if it exists
# at a different commit -- never retag.
- name: Create tag
run: |
TAG="v${{ github.event.inputs.version }}"
# checkout doesn't fetch tags; pull this one if it exists remotely.
git fetch --force origin "refs/tags/$TAG:refs/tags/$TAG" 2>/dev/null || true
if EXISTING=$(git rev-parse -q --verify "refs/tags/$TAG^{commit}"); then
if [ "$EXISTING" = "$(git rev-parse HEAD)" ]; then
echo "Tag $TAG already exists at HEAD; skipping tag creation."
else
echo "::error::Tag $TAG already exists at $EXISTING, but HEAD is $(git rev-parse HEAD). Refusing to retag."
exit 1
fi
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "$TAG"
git push origin "$TAG"
fi
- name: Publish to RubyGems
uses: rubygems/release-gem@v1
# Mirror release: the same content ships under the forward-looking gem
# name snap_diff-capybara with an identical version. The mirror gemspec
# is generated here (not committed) so local `gem build` and the
# Gemfile's `gemspec` directive stay unambiguous. Requires the
# snap_diff-capybara gem on rubygems.org to trust this repo+workflow
# as a trusted publisher.
# No separate credential setup: release-gem above already configured
# trusted-publishing credentials, and the temporary key covers any gem
# whose rubygems.org settings trust this repo+workflow.
- name: Publish snap_diff-capybara mirror to RubyGems
run: |
ruby -e '
spec = Gem::Specification.load("capybara-screenshot-diff.gemspec")
spec.name = "snap_diff-capybara"
File.write("snap_diff-capybara.gemspec", spec.to_ruby)
'
gem build snap_diff-capybara.gemspec
gem push "snap_diff-capybara-${{ github.event.inputs.version }}.gem"
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: "v${{ github.event.inputs.version }}"
name: "v${{ github.event.inputs.version }}"
prerelease: ${{ steps.verify.outputs.prerelease }}
make_latest: ${{ steps.verify.outputs.prerelease == 'false' }}
body: |
## What's Changed
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/v${{ github.event.inputs.version }}/CHANGELOG.md) for full details.
**Upgrade Guide:** [docs/UPGRADING.md](https://github.com/${{ github.repository }}/blob/v${{ github.event.inputs.version }}/docs/UPGRADING.md)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}