-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (152 loc) · 5.35 KB
/
ci-cd.yml
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
name: CI/CD
on:
push:
paths-ignore:
- '*.md'
workflow_dispatch:
inputs:
create_release:
description: 'Create a release? Set to true'
required: true
push_gem:
description: 'Push gem? Set to true'
required: true
jobs:
editorconfig:
name: Check EditorConfig
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Download editorconfig-checker
run: curl -O -L -C - https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.3.5/ec-linux-amd64.tar.gz
- name: Extract editorconfig-checker
run: tar xzf ec-linux-amd64.tar.gz
- name: Check EditorConfig compliance
run: ./bin/ec-linux-amd64
build-and-test:
name: Build & test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'
- name: Fetch Google Cloud credentials
run: echo "$CREDENTIALS" > credentials.json
env:
CREDENTIALS: ${{ secrets.TEST_GCLOUD_CREDENTIALS }}
- uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install Bundler 2
run: gem install bundler -v '~> 2.1' --no-document
- name: Bundle install
run: |
set -x
bundle config set path vendor/bundle
bundle config set frozen true
bundle install --jobs 4 --retry 3 --without=development
bundle clean
- name: Run RSpec
run: bundle exec rspec
env:
TEST_GCLOUD_BUCKET: ${{ secrets.TEST_GCLOUD_BUCKET }}
TEST_GCLOUD_CREDENTIALS_PATH: credentials.json
- name: Run Rubocop
run: bundle exec rake rubocop
- name: Generate Yard API docs
run: bundle exec yard && touch doc/.nojekyll
- name: Generate Sorbet type definitions
run: mkdir defs && bundle exec sord defs/defs.rbi
- run: gem build distributed-lock-google-cloud-storage.gemspec
- uses: actions/upload-artifact@v2
with:
name: gem
path: '*.gem'
- uses: actions/upload-artifact@v2
with:
name: api-docs
path: doc
publish:
name: Publish
needs:
- editorconfig
- build-and-test
if: |
github.ref == 'refs/heads/test/ci-cd'
|| github.event.inputs.create_release == 'true'
|| github.event.inputs.push_gem == 'true'
runs-on: ubuntu-20.04
environment: RubyGems.org
permissions:
contents: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --tags
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'
- uses: actions/download-artifact@v2
with:
name: gem
path: .
- uses: actions/download-artifact@v2
with:
name: api-docs
path: doc
- name: Determine version
id: determine_version
run: |
VERSION=$(ruby -r./lib/distributed-lock-google-cloud-storage/version -e 'puts DistributedLock::GoogleCloudStorage::Version::VERSION_STRING')
echo "::set-output name=version::$VERSION"
- name: Determine changelog
run: |
MERGE_BASE=$(git merge-base origin/main HEAD)
echo "Merge base: $MERGE_BASE"
if PREVIOUS_RELEASE_TAG=$(git describe "$MERGE_BASE" --tags --abbrev=0 --match='v*' 2>/dev/null); then
echo "Previous release: $PREVIOUS_RELEASE_TAG"
git log --pretty='format:%s' "$PREVIOUS_RELEASE_TAG..HEAD" | sed -E 's|(.*)| * \1|' > changelog.txt
else
echo "No previous release found"
git log --pretty='format:%s' | sed -E 's|(.*)| * \1|' > changelog.txt
fi
echo
echo "## Changelog"
cat changelog.txt
- name: Create tag
if: github.event.inputs.create_release == 'true'
run: |
set -x
git tag "v${PRODUCT_VERSION}"
git push origin "v${PRODUCT_VERSION}"
env:
PRODUCT_VERSION: ${{ steps.determine_version.outputs.version }}
- name: Create draft release
if: github.event.inputs.create_release == 'true'
run: gh release create "v${PRODUCT_VERSION}" --draft --notes-file changelog.txt --title "Version $PRODUCT_VERSION"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRODUCT_VERSION: ${{ steps.determine_version.outputs.version }}
- name: Upload release assets
if: github.event.inputs.create_release == 'true'
run: gh release upload --clobber "v${PRODUCT_VERSION}" *.gem
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRODUCT_VERSION: ${{ steps.determine_version.outputs.version }}
- name: Publish API docs
if: github.event.inputs.create_release == 'true'
uses: JamesIves/github-pages-deploy-action@0f24da7de3e7e135102609a4c9633b025be8411b
with:
branch: gh-pages
folder: doc
- name: Push gem
if: github.event.inputs.push_gem == 'true'
uses: dawidd6/action-publish-gem@c4713bf1595e0686322d6cf6c1a1c0dcaeca55de
with:
api_key: ${{ secrets.RUBYGEMS_API_KEY }}