Skip to content

Commit 179e85a

Browse files
committed
Get started
1 parent a2c514c commit 179e85a

10 files changed

+135
-197
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist/index.js linguist-generated
2+
/package-lock.json linguist-generated

.github/workflows/direct.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ jobs:
66
fail-fast: false
77
matrix:
88
os: [ 'ubuntu-16.04', 'ubuntu-18.04', 'macos-latest' ]
9-
ruby: [ 'ruby-2.6.5', 'ruby-2.7.0' ]
9+
ruby: [ 'ruby-2.6.5', 'ruby-2.7.0', 'truffleruby-19.3.0', 'jruby-9.2.9.0' ]
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- run: echo ::set-env name=HOME::$HOME
1313
- run: mkdir ~/.rubies
14-
- run: wget -O ~/.rubies/${{ matrix.ruby }}-${{ matrix.os }}.tar.gz https://github.com/eregon/ruby-install-builder/releases/download/builds/${{ matrix.ruby }}-${{ matrix.os }}.tar.gz
14+
- run: wget https://github.com/eregon/ruby-install-builder/releases/download/builds/${{ matrix.ruby }}-${{ matrix.os }}.tar.gz
15+
working-directory: ${{ env.HOME }}/.rubies
1516
- run: tar xf ${{ matrix.ruby }}-${{ matrix.os }}.tar.gz
1617
working-directory: ${{ env.HOME }}/.rubies
1718
- run: echo "::add-path::${{ env.HOME }}/.rubies/${{ matrix.ruby }}/bin"

.github/workflows/test.yml

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
name: "units-test"
2-
on:
3-
pull_request:
4-
push:
5-
branches:
6-
- master
7-
- 'releases/*'
8-
1+
name: Test this action
2+
on: [push]
93
jobs:
10-
# unit tests
11-
units:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v1
15-
- run: npm ci
16-
- run: npm test
17-
18-
# test action works running from the graph
194
test:
20-
runs-on: ubuntu-latest
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
os: [ 'ubuntu-16.04', 'ubuntu-18.04', 'macos-latest' ]
9+
ruby: [ 'ruby-2.6.5', 'ruby-2.7.0', 'truffleruby-19.3.0', 'jruby-9.2.9.0' ]
10+
runs-on: ${{ matrix.os }}
2111
steps:
22-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v2
2313
- uses: ./
2414
with:
25-
milliseconds: 1000
15+
ruby-version: ${{ matrix.ruby }}
16+
- run: ruby -v
17+
- run: ruby -ropen-uri -e 'puts open("https://rubygems.org/") { |f| f.read(2014) }'

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 GitHub Actions
3+
Copyright (c) 2019 Benoit Daloze
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+47-104
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,57 @@
1+
# use-ruby
12

2-
<p align="center">
3-
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a>
4-
</p>
3+
This action downloads a prebuilt ruby and adds it to `$PATH`.
54

6-
# Create a JavaScript Action
5+
It currently supports the latest stable versions of MRI, JRuby and TruffleRuby.
76

8-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
9-
10-
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
11-
12-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
13-
14-
## Create an action from this template
15-
16-
Click the `Use this Template` and provide the new repo details for your action
17-
18-
## Code in Master
19-
20-
Install the dependencies
21-
```bash
22-
$ npm install
23-
```
24-
25-
Run the tests :heavy_check_mark:
26-
```bash
27-
$ npm test
28-
29-
PASS ./index.test.js
30-
✓ throws invalid number (3ms)
31-
wait 500 ms (504ms)
32-
test runs (95ms)
33-
34-
...
35-
```
36-
37-
## Change action.yml
38-
39-
The action.yml contains defines the inputs and output for your action.
40-
41-
Update the action.yml with your name, description, inputs and outputs for your action.
42-
43-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
44-
45-
## Change the Code
46-
47-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
48-
49-
```javascript
50-
const core = require('@actions/core');
51-
...
52-
53-
async function run() {
54-
try {
55-
...
56-
}
57-
catch (error) {
58-
core.setFailed(error.message);
59-
}
60-
}
61-
62-
run()
63-
```
64-
65-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
66-
67-
## Package for distribution
68-
69-
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
70-
71-
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
72-
73-
Run package
74-
75-
```bash
76-
npm run package
77-
```
78-
79-
Since the packaged index.js is run from the dist folder.
80-
81-
```bash
82-
git add dist
83-
```
84-
85-
## Create a release branch
86-
87-
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
88-
89-
Checkin to the v1 release branch
90-
91-
```bash
92-
$ git checkout -b v1
93-
$ git commit -a -m "v1 release"
94-
```
95-
96-
```bash
97-
$ git push origin v1
98-
```
99-
100-
Your action is now published! :rocket:
101-
102-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
7+
See https://github.com/eregon/ruby-install-builder/releases/tag/builds for the
8+
available Ruby versions.
1039

10410
## Usage
10511

106-
You can now consume the action by referencing the v1 branch
12+
Single job:
10713

10814
```yaml
109-
uses: actions/javascript-action@v1
110-
with:
111-
milliseconds: 1000
15+
name: My workflow
16+
on: [push]
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: eregon/use-ruby-action@master
23+
with:
24+
ruby-version: ruby-2.6.5
25+
- run: ruby -v
11226
```
11327
114-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
28+
Matrix:
29+
30+
```yaml
31+
name: My workflow
32+
on: [push]
33+
jobs:
34+
test:
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os: [ 'ubuntu-latest', 'macos-latest' ]
39+
ruby: [ 'ruby-2.6.5', 'ruby-2.7.0', 'truffleruby-19.3.0', 'jruby-9.2.9.0' ]
40+
runs-on: ${{ matrix.os }}
41+
steps:
42+
- uses: actions/checkout@v2
43+
- uses: eregon/use-ruby-action@master
44+
with:
45+
ruby-version: ${{ matrix.ruby }}
46+
- run: ruby -v
47+
```
48+
49+
## Efficiency
50+
51+
It takes about 5 seconds to setup the given Ruby.
52+
53+
## Limitations
54+
55+
* Currently does not work on Windows since the builder doesn't build on Windows.
56+
https://github.com/MSP-Greg/actions-ruby is an alternative on Windows.
57+
* This action currently only works with GitHub-hosted runners, not private runners.

action.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
name: 'Wait'
2-
description: 'Wait a designated number of milliseconds'
1+
name: 'use-ruby'
2+
description: 'Download a prebuilt ruby and add it to $PATH'
33
inputs:
4-
milliseconds: # id of input
5-
description: 'number of milliseconds to wait'
4+
ruby-version:
5+
description: 'Version of ruby to use in the format "X.Y.Z"'
66
required: true
7-
default: '1000'
87
outputs:
9-
time: # output will be available to future steps
10-
description: 'The message to output'
8+
ruby-prefix:
9+
description: 'The prefix of the installed ruby'
1110
runs:
1211
using: 'node12'
1312
main: 'dist/index.js'

index.js

+51-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
1-
const core = require('@actions/core');
2-
const wait = require('./wait');
1+
const core = require('@actions/core')
2+
const io = require('@actions/io')
3+
const tc = require('@actions/tool-cache')
4+
const os = require('os')
5+
const fs = require('fs')
36

4-
5-
// most @actions toolkit packages have async methods
67
async function run() {
7-
try {
8-
const ms = core.getInput('milliseconds');
9-
console.log(`Waiting ${ms} milliseconds ...`)
10-
11-
core.debug((new Date()).toTimeString())
12-
wait(parseInt(ms));
13-
core.debug((new Date()).toTimeString())
14-
15-
core.setOutput('time', new Date().toTimeString());
16-
}
17-
catch (error) {
18-
core.setFailed(error.message);
8+
try {
9+
const rubyVersion = core.getInput('ruby-version')
10+
11+
let ruby = rubyVersion
12+
if (!ruby.includes('-')) {
13+
ruby = 'ruby-' + ruby;
14+
}
15+
16+
const rubiesDir = `${process.env.HOME}/.rubies`
17+
await io.mkdirP(rubiesDir)
18+
19+
const platform = getVirtualEnvironmentName()
20+
const url = `https://github.com/eregon/ruby-install-builder/releases/download/builds/${ruby}-${platform}.tar.gz`
21+
console.log(url)
22+
23+
const downloadPath = await tc.downloadTool(url)
24+
await tc.extractTar(downloadPath, rubiesDir)
25+
26+
const rubyPrefix = `${rubiesDir}/${ruby}`
27+
core.addPath(`${rubyPrefix}/bin`)
28+
core.setOutput('ruby-prefix', rubyPrefix)
29+
} catch (error) {
30+
core.setFailed(error.message)
31+
}
32+
}
33+
34+
function getVirtualEnvironmentName() {
35+
const platform = os.platform()
36+
if (platform == 'linux') {
37+
return `ubuntu-${findUbuntuVersion()}`
38+
} else if (platform == 'darwin') {
39+
return 'macos-latest'
40+
} else if (platform == 'win32') {
41+
return 'windows-latest'
42+
} else {
43+
throw new Error(`Unknown platform ${platform}`)
44+
}
45+
}
46+
47+
function findUbuntuVersion() {
48+
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
49+
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
50+
if (match) {
51+
return match[1]
52+
} else {
53+
throw new Error('Could not find Ubuntu version')
1954
}
2055
}
2156

index.test.js

-23
This file was deleted.

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
{
2-
"name": "javascript-action",
3-
"version": "1.0.0",
4-
"description": "JavaScript Action Template",
2+
"name": "use-ruby-action",
3+
"version": "0.1.0",
4+
"description": "Download a prebuilt ruby and add it to $PATH",
55
"main": "index.js",
66
"scripts": {
77
"lint": "eslint index.js",
8-
"package": "ncc build index.js -o dist",
9-
"test": "eslint index.js && jest"
8+
"package": "ncc build index.js -o dist"
109
},
1110
"repository": {
1211
"type": "git",
13-
"url": "git+https://github.com/actions/javascript-action.git"
12+
"url": "git+https://github.com/eregon/use-ruby-action.git"
1413
},
1514
"keywords": [
1615
"GitHub",
1716
"Actions",
18-
"JavaScript"
17+
"Ruby"
1918
],
20-
"author": "GitHub",
19+
"author": "Benoit Daloze",
2120
"license": "MIT",
2221
"bugs": {
23-
"url": "https://github.com/actions/javascript-action/issues"
22+
"url": "https://github.com/eregon/use-ruby-action/issues"
2423
},
25-
"homepage": "https://github.com/actions/javascript-action#readme",
24+
"homepage": "https://github.com/eregon/use-ruby-action",
2625
"dependencies": {
27-
"@actions/core": "^1.1.1"
26+
"@actions/core": "^1.1.1",
27+
"@actions/io": "^1.0.1",
28+
"@actions/tool-cache": "^1.1.2"
2829
},
2930
"devDependencies": {
3031
"@zeit/ncc": "^0.20.5",
31-
"eslint": "^6.3.0",
32-
"jest": "^24.9.0"
32+
"eslint": "^6.3.0"
3333
}
3434
}

0 commit comments

Comments
 (0)