Skip to content

Commit 1a2de94

Browse files
authored
repo sync
2 parents b6de7c6 + c829a98 commit 1a2de94

File tree

72 files changed

+862
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+862
-248
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
---
2+
title: Building and testing Ruby
3+
intro: You can create a continuous integration (CI) workflow to build and test your Ruby project.
4+
product: '{% data reusables.gated-features.actions %}'
5+
versions:
6+
free-pro-team: '*'
7+
enterprise-server: '>=2.22'
8+
---
9+
10+
{% data reusables.actions.enterprise-beta %}
11+
{% data reusables.actions.enterprise-github-hosted-runners %}
12+
13+
### Introduction
14+
15+
This guide shows you how to create a continuous integration (CI) workflow that builds and tests a Ruby application. If your CI tests pass, you may want to deploy your code or publish a gem.
16+
17+
### Prerequisites
18+
19+
We recommend that you have a basic understanding of Ruby, YAML, workflow configuration options, and how to create a workflow file. For more information, see:
20+
21+
- [Learn {% data variables.product.prodname_actions %}](/actions/learn-github-actions)
22+
- [Ruby in 20 minutes](https://www.ruby-lang.org/en/documentation/quickstart/)
23+
24+
### Starting with the Ruby workflow template
25+
26+
{% data variables.product.prodname_dotcom %} provides a Ruby workflow template that will work for most Ruby projects. For more information, see the [Ruby workflow template](https://github.com/actions/starter-workflows/blob/master/ci/ruby.yml).
27+
28+
To get started quickly, add the template to the `.github/workflows` directory of your repository.
29+
30+
{% raw %}
31+
```yaml
32+
name: Ruby
33+
34+
on:
35+
push:
36+
branches: [ $default-branch ]
37+
pull_request:
38+
branches: [ $default-branch ]
39+
40+
jobs:
41+
test:
42+
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v2
47+
- name: Set up Ruby
48+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
49+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
50+
# uses: ruby/setup-ruby@v1
51+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
52+
with:
53+
ruby-version: 2.6
54+
- name: Install dependencies
55+
run: bundle install
56+
- name: Run tests
57+
run: bundle exec rake
58+
```
59+
{% endraw %}
60+
61+
### Specifying the Ruby version
62+
63+
The easiest way to specify a Ruby version is by using the `ruby/setup-ruby` action provided by the Ruby organization on GitHub. The action adds any supported Ruby version to `PATH` for each job run in a workflow. For more information see, the [`ruby/setup-ruby`](https://github.com/ruby/setup-ruby).
64+
65+
Using either Ruby's `ruby/setup-ruby` action or GitHub's `actions/setup-ruby` action is the recommended way of using Ruby with GitHub Actions because it ensures consistent behavior across different runners and different versions of Ruby.
66+
67+
The `setup-ruby` action takes a Ruby version as an input and configures that version on the runner.
68+
69+
{% raw %}
70+
```yaml
71+
steps:
72+
- uses: actions/checkout@v2
73+
- uses: ruby/setup-ruby@v1
74+
with:
75+
ruby-version: 2.6 # Not needed with a .ruby-version file
76+
- run: bundle install
77+
- run: bundle exec rake
78+
```
79+
{% endraw %}
80+
81+
Alternatively, you can check a `.ruby-version` file into the root of your repository and `setup-ruby` will use the version defined in that file.
82+
83+
### Testing with multiple versions of Ruby
84+
85+
You can add a matrix strategy to run your workflow with more than one version of Ruby. For example, you can test your code against the latest patch releases of versions 2.7, 2.6, and 2.5. The 'x' is a wildcard character that matches the latest patch release available for a version.
86+
87+
{% raw %}
88+
```yaml
89+
strategy:
90+
matrix:
91+
ruby-version: [2.7.x, 2.6.x, 2.5.x]
92+
```
93+
{% endraw %}
94+
95+
Each version of Ruby specified in the `ruby-version` array creates a job that runs the same steps. The {% raw %}`${{ matrix.ruby-version }}`{% endraw %} context is used to access the current job's version. For more information about matrix strategies and contexts, see "Workflow syntax for GitHub Actions" and "Context and expression syntax for GitHub Actions."
96+
97+
The full updated workflow with a matrix strategy could look like this:
98+
99+
{% raw %}
100+
```yaml
101+
name: Ruby CI
102+
103+
on:
104+
push:
105+
branches: [ $default-branch ]
106+
pull_request:
107+
branches: [ $default-branch ]
108+
109+
jobs:
110+
test:
111+
112+
runs-on: ubuntu-latest
113+
114+
strategy:
115+
matrix:
116+
ruby-version: [2.7.x, 2.6.x, 2.5.x]
117+
118+
steps:
119+
- uses: actions/checkout@v2
120+
- name: Set up Ruby ${{ matrix.ruby-version }}
121+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
122+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
123+
# uses: ruby/setup-ruby@v1
124+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
125+
with:
126+
ruby-version: ${{ matrix.ruby-version }}
127+
- name: Install dependencies
128+
run: bundle install
129+
- name: Run tests
130+
run: bundle exec rake
131+
```
132+
{% endraw %}
133+
134+
### Installing dependencies with Bundler
135+
136+
The `setup-ruby` action will automatically install bundler for you. The version is determined by your `gemfile.lock` file. If no version is present in your lockfile, then the latest compatible version will be installed.
137+
138+
{% raw %}
139+
```yaml
140+
steps:
141+
- uses: actions/checkout@v2
142+
- uses: ruby/setup-ruby@v1
143+
with:
144+
ruby-version: 2.6
145+
- run: bundle install
146+
```
147+
{% endraw %}
148+
149+
#### Caching dependencies
150+
151+
The `setup-ruby` actions provides a method to automatically handle the caching of your gems between runs.
152+
153+
To enable caching, set the following.
154+
155+
{% raw %}
156+
```yaml
157+
steps:
158+
- uses: ruby/setup-ruby@v1
159+
with:
160+
bundler-cache: true
161+
```
162+
{% endraw %}
163+
164+
This will configure bundler to install your gems to `vendor/cache`. For each successful run of your workflow, this folder will be cached by Actions and re-downloaded for subsequent workflow runs. A hash of your gemfile.lock and the Ruby version are used as the cache key. If you install any new gems, or change a version, the cache will be invalidated and bundler will do a fresh install.
165+
166+
**Caching without setup-ruby**
167+
168+
For greater control over caching, you can use the `actions/cache` Action directly. For more information, see "[Caching dependencies to speed up your workflow](/actions/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows)."
169+
170+
{% raw %}
171+
```yaml
172+
steps:
173+
- uses: actions/cache@v2
174+
with:
175+
path: vendor/bundle
176+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
177+
restore-keys: |
178+
${{ runner.os }}-gems-
179+
- name: Bundle install
180+
run: |
181+
bundle config path vendor/bundle
182+
bundle install --jobs 4 --retry 3
183+
```
184+
{% endraw %}
185+
186+
If you're using a matrix build, you will want to include the matrix variables in your cache key. For example, if you have a matrix strategy for different ruby versions (`matrix.ruby-version`) and different operating systems (`matrix.os`), your workflow steps might look like this:
187+
188+
{% raw %}
189+
```yaml
190+
steps:
191+
- uses: actions/cache@v2
192+
with:
193+
path: vendor/bundle
194+
key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }}
195+
restore-keys: |
196+
bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby-version }}-
197+
- name: Bundle install
198+
run: |
199+
bundle config path vendor/bundle
200+
bundle install --jobs 4 --retry 3
201+
```
202+
{% endraw %}
203+
204+
### Matrix testing your code
205+
206+
The following example matrix tests all stable releases and head versions of MRI, JRuby and TruffleRuby on Ubuntu and macOS.
207+
208+
{% raw %}
209+
```yaml
210+
name: Matrix Testing
211+
212+
on:
213+
push:
214+
branches: [ $default-branch ]
215+
pull_request:
216+
branches: [ $default-branch ]
217+
218+
jobs:
219+
test:
220+
runs-on: ${{ matrix.os }}-latest
221+
strategy:
222+
fail-fast: false
223+
matrix:
224+
os: [ubuntu, macos]
225+
ruby: [2.5, 2.6, 2.7, head, debug, jruby, jruby-head, truffleruby, truffleruby-head]
226+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
227+
steps:
228+
- uses: actions/checkout@v2
229+
- uses: ruby/setup-ruby@v1
230+
with:
231+
ruby-version: ${{ matrix.ruby }}
232+
- run: bundle install
233+
- run: bundle exec rake
234+
```
235+
{% endraw %}
236+
237+
### Linting your code
238+
239+
The following example installs `rubocop` and uses it to lint all files. For more information, see [Rubocop](https://github.com/rubocop-hq/rubocop). You can [configure Rubocop](https://docs.rubocop.org/rubocop/configuration.html) to decide on the specific linting rules.
240+
241+
{% raw %}
242+
```yaml
243+
name: Linting
244+
245+
on: [push]
246+
247+
jobs:
248+
test:
249+
runs-on: ubuntu-latest
250+
steps:
251+
- uses: actions/checkout@v2
252+
- uses: ruby/setup-ruby@v1
253+
with:
254+
ruby-version: 2.6
255+
- run: bundle install
256+
- name: Rubocop
257+
run: rubocop
258+
```
259+
{% endraw %}
260+
261+
### Publishing Gems
262+
263+
You can configure your workflow to publish your Ruby package to any package registry you'd like when your CI tests pass.
264+
265+
You can store any access tokens or credentials needed to publish your package using repository secrets. The following example creates and publishes a package to `GitHub Package Registry` and `RubyGems`.
266+
267+
{% raw %}
268+
```yaml
269+
270+
name: Ruby Gem
271+
272+
on:
273+
# Manually publish
274+
workflow_dispatch:
275+
# Alternatively, publish whenever changes are merged to the default branch.
276+
push:
277+
branches: [ $default-branch ]
278+
pull_request:
279+
branches: [ $default-branch ]
280+
281+
jobs:
282+
build:
283+
name: Build + Publish
284+
runs-on: ubuntu-latest
285+
286+
steps:
287+
- uses: actions/checkout@v2
288+
- name: Set up Ruby 2.6
289+
uses: ruby/setup-ruby@v1
290+
with:
291+
ruby-version: 2.6
292+
- run: bundle install
293+
294+
- name: Publish to GPR
295+
run: |
296+
mkdir -p $HOME/.gem
297+
touch $HOME/.gem/credentials
298+
chmod 0600 $HOME/.gem/credentials
299+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
300+
gem build *.gemspec
301+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
302+
env:
303+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
304+
OWNER: ${{ github.repository_owner }}
305+
306+
- name: Publish to RubyGems
307+
run: |
308+
mkdir -p $HOME/.gem
309+
touch $HOME/.gem/credentials
310+
chmod 0600 $HOME/.gem/credentials
311+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
312+
gem build *.gemspec
313+
gem push *.gem
314+
env:
315+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
316+
```
317+
{% endraw %}
318+

content/actions/guides/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You can use {% data variables.product.prodname_actions %} to create custom conti
3131
{% link_in_list /building-and-testing-nodejs %}
3232
{% link_in_list /building-and-testing-powershell %}
3333
{% link_in_list /building-and-testing-python %}
34+
{% link_in_list /building-and-testing-ruby %}
3435
{% link_in_list /building-and-testing-java-with-maven %}
3536
{% link_in_list /building-and-testing-java-with-gradle %}
3637
{% link_in_list /building-and-testing-java-with-ant %}

content/actions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ versions:
7979
<div class="mb-3">{% octicon "search" width="24" %}</div>
8080
<h3 class="text-normal">Sorry, there is no result for <strong class="js-code-example-filter-value"></strong></h3>
8181
<p class="my-3 f4">It looks like we don't have an example that fits your filter.<br>Try another filter or add your code example</p>
82-
<a href="https://github.com/github/docs/blob/HEAD/data/variables/action_code_examples.yml">Learn how to add a code example {% octicon "arrow-right" %}</a>
82+
<a href="https://github.com/github/docs/blob/main/data/variables/action_code_examples.yml">Learn how to add a code example {% octicon "arrow-right" %}</a>
8383
</div>
8484
</div>
8585
{% endif %}

content/admin/enterprise-management/configuring-collectd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ versions:
1010
---
1111
### Set up an external `collectd` server
1212

13-
If you haven't already set up an external `collectd` server, you will need to do so before enabling `collectd` forwarding on {% data variables.product.product_location %}. Your `collectd` server must by running `collectd` version 5.x or higher.
13+
If you haven't already set up an external `collectd` server, you will need to do so before enabling `collectd` forwarding on {% data variables.product.product_location %}. Your `collectd` server must be running `collectd` version 5.x or higher.
1414

1515
1. Log into your `collectd` server.
1616
2. Create or edit the `collectd` configuration file to load the network plugin and populate the server and port directives with the proper values. On most distributions, this is located at `/etc/collectd/collectd.conf`

content/admin/packages/configuring-third-party-storage-for-packages.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ For the best experience, we recommend using a dedicated bucket for {% data varia
2121

2222
{% warning %}
2323

24-
**Warning:** Make sure to configure the bucket you'll want to use in the future. We do not recommend changing your storage after you start using {% data variables.product.prodname_registry %}.
24+
**Warnings:**
25+
- It's critical you set the restrictive access policies you want for your storage bucket because {% data variables.product.company_short %} does not apply specific object permissions or additional access control lists (ACLs) to your storage bucket configuration. For example, if you make your bucket public, data in the bucket will be accessible on the public internet. For more information, see [Setting bucket and object access permissions](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/set-permissions.html) in the AWS Documentation.
26+
- We recommend using a dedicated bucket for {% data variables.product.prodname_registry %}, separate from the bucket you use for {% data variables.product.prodname_actions %} storage.
27+
- Make sure to configure the bucket you'll want to use in the future. We do not recommend changing your storage after you start using {% data variables.product.prodname_registry %}.
2528

2629
{% endwarning %}
2730

content/admin/packages/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: Managing GitHub Packages for your enterprise
3-
shortTitle: GitHub Packages
43
intro: 'You can enable {% data variables.product.prodname_registry %} for your enterprise and manage {% data variables.product.prodname_registry %} settings and allowed packaged types.'
54
redirect_from:
65
- /enterprise/admin/packages

0 commit comments

Comments
 (0)