-
Notifications
You must be signed in to change notification settings - Fork 3
173 lines (157 loc) · 5.73 KB
/
release.yml
File metadata and controls
173 lines (157 loc) · 5.73 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
name: Release Gem + Sync Terraform Provider
on:
release:
types: [published]
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (no pushes/tags/uploads)'
required: false
default: 'false'
type: choice
options: ['false', 'true']
permissions:
contents: read
jobs:
sync:
name: Release gem and sync provider
runs-on: ubuntu-latest
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true' && 'true' || 'false' }}
TAG_NAME: ${{ github.ref_type == 'tag' && github.ref_name || github.event.release.tag_name }}
steps:
- name: Checkout logstruct
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '.ruby-version'
bundler-cache: true
- name: Setup Node (for pnpm cache if needed)
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Determine version and validate tag
id: ver
shell: bash
run: |
TAG="${TAG_NAME:-}"
if [[ -z "$TAG" ]]; then
echo "No tag resolved; using release event tag." >&2
TAG="${{ github.event.release.tag_name }}"
fi
if [[ -z "$TAG" ]]; then
if [[ "$DRY_RUN" == "true" ]]; then
TAG="v0.0.0-dryrun"
echo "DRY-RUN: Using placeholder tag $TAG" >&2
else
echo "Error: Could not determine tag name from event." >&2
exit 1
fi
fi
VERSION_FROM_TAG="${TAG#v}"
VERSION_RB=$(ruby -e 'print File.read("lib/log_struct/version.rb")[/VERSION\s*=\s*"([^"]+)"/,1]')
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version_tag=$VERSION_FROM_TAG" >> $GITHUB_OUTPUT
echo "version_rb=$VERSION_RB" >> $GITHUB_OUTPUT
echo "Resolved tag: $TAG (version $VERSION_FROM_TAG); code version: $VERSION_RB"
if [[ "$DRY_RUN" != "true" && "$VERSION_FROM_TAG" != "$VERSION_RB" ]]; then
echo "::error::Tag version ($VERSION_FROM_TAG) does not match lib/log_struct/version.rb ($VERSION_RB). Update version.rb before tagging, or run as dry-run."
exit 1
fi
- name: Generate site exports (enums/structs/keys)
run: |
ruby scripts/export_typescript_types.rb
- name: Build gem
run: |
gem build logstruct.gemspec
ls -la *.gem
- name: Publish gem to RubyGems
if: env.DRY_RUN != 'true'
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
if [[ -z "$RUBYGEMS_API_KEY" ]]; then
echo '::error::RUBYGEMS_API_KEY secret is missing.'
exit 1
fi
mkdir -p ~/.gem
umask 077
cat > ~/.gem/credentials <<EOF
---
:rubygems_api_key: $RUBYGEMS_API_KEY
EOF
GEM_FILE="logstruct-${{ steps.ver.outputs.version_tag }}.gem"
if [[ ! -f "$GEM_FILE" ]]; then
echo "::error::Expected gem file $GEM_FILE not found."
ls -la *.gem || true
exit 1
fi
gem push "$GEM_FILE"
- name: Gem publish (dry-run)
if: env.DRY_RUN == 'true'
run: |
echo "[DRY-RUN] Would push gem logstruct-${{ steps.ver.outputs.version_tag }}.gem to RubyGems"
- name: Clone terraform-provider-logstruct repository
env:
PUSH_TOKEN: ${{ secrets.PROVIDER_PUSH_TOKEN }}
run: |
git config --global user.name "DocSpring Bot"
git config --global user.email "docspring-bot@docspring.com"
rm -rf terraform-provider-logstruct
git clone https://x-access-token:${PUSH_TOKEN}@github.com/DocSpring/terraform-provider-logstruct.git terraform-provider-logstruct
- name: Export provider catalog (embedded Go data)
run: |
ruby scripts/export_provider_catalog.rb
- name: Build provider to validate catalog
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Compile
run: |
cd terraform-provider-logstruct
go mod tidy
go build ./...
- name: Commit and push provider changes
env:
PUSH_TOKEN: ${{ secrets.PROVIDER_PUSH_TOKEN }}
run: |
cd terraform-provider-logstruct
if git diff --quiet; then
echo "No provider changes to commit."
exit 0
fi
git add pkg/data/catalog_gen.go pkg/data/catalog.json go.mod go.sum || true
if [[ "$DRY_RUN" == "true" ]]; then
echo "[DRY-RUN] Would commit and push provider catalog changes with message:"
echo "Sync catalog from logstruct ${{ steps.ver.outputs.tag }}"
git --no-pager diff --staged || true
else
git commit -m "Sync catalog from logstruct ${{ steps.ver.outputs.tag }}"
git push origin HEAD:main
fi
- name: Tag provider with release version
env:
PUSH_TOKEN: ${{ secrets.PROVIDER_PUSH_TOKEN }}
run: |
cd terraform-provider-logstruct
TAG="${{ steps.ver.outputs.tag }}"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "Tag $TAG already exists; skipping."
exit 0
fi
if [[ "$DRY_RUN" == "true" ]]; then
echo "[DRY-RUN] Would create and push tag $TAG"
else
git tag -a "$TAG" -m "Release $TAG (logstruct sync)"
git push origin "$TAG"
fi