|
1 | 1 | <p align="center">
|
2 |
| - <a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a> |
| 2 | + <a href="https://github.com/rubygems/configure-rubygems-credentials/actions"> |
| 3 | + <img alt="configure-rubygems-credentials-action status" src="https://github.com/rubygems/configure-rubygems-credentials/workflows/build-test/badge.svg"> |
| 4 | + </a> |
3 | 5 | </p>
|
4 | 6 |
|
5 |
| -# Create a JavaScript Action using TypeScript |
| 7 | +## Configure RubyGems Credentials for GitHub Actions |
6 | 8 |
|
7 |
| -Use this template to bootstrap the creation of a TypeScript action.:rocket: |
| 9 | +Configure your RubyGems credentials and for use in other |
| 10 | +GitHub Actions. This action implements OIDC support, writes gem credentials files, |
| 11 | +and exports environment variables used by both `rubygems` and |
| 12 | +`bundler` for your other Actions to use. |
8 | 13 |
|
9 |
| -This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance. |
| 14 | +### Table of Contents |
10 | 15 |
|
11 |
| -If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) |
| 16 | +<!-- toc --> |
12 | 17 |
|
13 |
| -## Create an action from this template |
| 18 | +- [Usage](#usage) |
| 19 | + - [Examples](#examples) |
| 20 | + - [OIDC (recommended)](#oidc-recommended) |
| 21 | + - [Static API token in repository secrets](#static-api-token-in-repository-secrets) |
| 22 | + - [Use with the RubyGems CLI](#use-with-the-rubygems-cli) |
| 23 | +- [License Summary](#license-summary) |
| 24 | +- [Security Disclosures](#security-disclosures) |
14 | 25 |
|
15 |
| -Click the `Use this Template` and provide the new repo details for your action |
| 26 | +<!-- tocstop --> |
16 | 27 |
|
17 |
| -## Code in Main |
| 28 | +## Usage |
18 | 29 |
|
19 |
| -> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance. |
| 30 | +We recommend that |
| 31 | +you use GitHub's OIDC provider in conjunction with a configured |
| 32 | +RubyGems OIDC API Key Role. |
20 | 33 |
|
21 |
| -Install the dependencies |
22 |
| -```bash |
23 |
| -$ npm install |
24 |
| -``` |
| 34 | +To do that, you would add the following step to your workflow: |
25 | 35 |
|
26 |
| -Build the typescript and package it for distribution |
27 |
| -```bash |
28 |
| -$ npm run build && npm run package |
| 36 | +```yaml |
| 37 | +- name: Configure RubyGems Credentials |
| 38 | + uses: rubygems/configure-rubygems-credentials@main |
| 39 | + with: |
| 40 | + role-to-assume: 3 |
29 | 41 | ```
|
30 | 42 |
|
31 |
| -Run the tests :heavy_check_mark: |
32 |
| -```bash |
33 |
| -$ npm test |
| 43 | +You can use this action with the `rubygems` or `bundler` command line tools, |
| 44 | +or run this action multiple times |
| 45 | +to use different RubyGems.org accounts or OIDC API Key roles in the same GitHub Actions |
| 46 | +workflow. As an example, here is a complete workflow file that pushes a gem release. |
34 | 47 |
|
35 |
| - PASS ./index.test.js |
36 |
| - ✓ throws invalid number (3ms) |
37 |
| - ✓ wait 500 ms (504ms) |
38 |
| - ✓ test runs (95ms) |
39 |
| - |
40 |
| -... |
| 48 | +```yaml |
| 49 | +on: |
| 50 | + - push |
| 51 | +
|
| 52 | +jobs: |
| 53 | + job: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + permissions: |
| 56 | + contents: write |
| 57 | + id-token: write |
| 58 | + steps: |
| 59 | + - uses: rubygems/configure-rubygems-credentials@main |
| 60 | + with: |
| 61 | + role-to-assume: 2 |
| 62 | + gem-server: 'https://oidc-api-token.rubygems.org' |
| 63 | + audience: 'https://oidc-api-token.rubygems.org' |
| 64 | + - uses: actions/checkout@v3 |
| 65 | + - name: Set remote URL |
| 66 | + run: | |
| 67 | + git config --global user.email "$(git log -1 --pretty=format:'%ae')" |
| 68 | + git config --global user.name "$(git log -1 --pretty=format:'%an')" |
| 69 | + git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" |
| 70 | + - name: Set up Ruby |
| 71 | + uses: ruby/setup-ruby@v1 |
| 72 | + with: |
| 73 | + ruby-version: '3.2.1' |
| 74 | + bundler-cache: true |
| 75 | + - name: Release |
| 76 | + run: bundle exec rake release |
41 | 77 | ```
|
42 | 78 |
|
43 |
| -## Change action.yml |
44 |
| - |
45 |
| -The action.yml defines the inputs and output for your action. |
46 |
| - |
47 |
| -Update the action.yml with your name, description, inputs and outputs for your action. |
48 |
| - |
49 |
| -See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) |
50 |
| - |
51 |
| -## Change the Code |
| 79 | +See [action.yml](action.yml) for the full documentation for this action's inputs |
| 80 | +and outputs. |
52 | 81 |
|
53 |
| -Most toolkit and CI/CD operations involve async operations so the action is run in an async function. |
| 82 | +### Examples |
54 | 83 |
|
55 |
| -```javascript |
56 |
| -import * as core from '@actions/core'; |
57 |
| -... |
| 84 | +#### OIDC (recommended) |
58 | 85 |
|
59 |
| -async function run() { |
60 |
| - try { |
61 |
| - ... |
62 |
| - } |
63 |
| - catch (error) { |
64 |
| - core.setFailed(error.message); |
65 |
| - } |
66 |
| -} |
67 |
| - |
68 |
| -run() |
| 86 | +```yaml |
| 87 | +- name: Configure RubyGems Credentials |
| 88 | + uses: rubygems/configure-rubygems-credentials@main |
| 89 | + with: |
| 90 | + role-to-assume: 3 |
69 | 91 | ```
|
70 | 92 |
|
71 |
| -See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. |
| 93 | +In this example, the Action will load the OIDC token from the GitHub-provided environment variable and use it to assume the role `3`. |
72 | 94 |
|
73 |
| -## Publish to a distribution branch |
| 95 | +#### Static API token in repository secrets |
74 | 96 |
|
75 |
| -Actions are run from GitHub repos so we will checkin the packed dist folder. |
76 |
| - |
77 |
| -Then run [ncc](https://github.com/zeit/ncc) and push the results: |
78 |
| -```bash |
79 |
| -$ npm run package |
80 |
| -$ git add dist |
81 |
| -$ git commit -a -m "prod dependencies" |
82 |
| -$ git push origin releases/v1 |
| 97 | +```yaml |
| 98 | +- name: Configure RubyGems Credentials |
| 99 | + uses: rubygems/configure-rubygems-credentials@main |
| 100 | + with: |
| 101 | + api-token: ${{ secrets.RUBYGEMS_API_TOKEN }} |
83 | 102 | ```
|
84 | 103 |
|
85 |
| -Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project. |
| 104 | +In this example, the secret `RUBYGEMS_API_TOKEN` contains a string like `rubygems_1a072a969ecdd84bb190c3c218e13e3c6f5d419f3f0f5b22`. |
86 | 105 |
|
87 |
| -Your action is now published! :rocket: |
| 106 | +### Use with the RubyGems CLI |
88 | 107 |
|
89 |
| -See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) |
| 108 | +This workflow does _not_ install the rubygems |
| 109 | +into your environment. |
90 | 110 |
|
91 |
| -## Validate |
92 |
| - |
93 |
| -You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)) |
94 |
| - |
95 |
| -```yaml |
96 |
| -uses: ./ |
97 |
| -with: |
98 |
| - milliseconds: 1000 |
99 |
| -``` |
| 111 | +## License Summary |
100 | 112 |
|
101 |
| -See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket: |
| 113 | +This code is made available under the MIT license. |
102 | 114 |
|
103 |
| -## Usage: |
| 115 | +## Security Disclosures |
104 | 116 |
|
105 |
| -After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action |
| 117 | +If you would like to report a potential security issue in this project, please do not create a GitHub issue. Instead, please follow the instructions [here](https://rubygems.org/pages/security) or [email the RubyGems security team](mailto:[email protected]). |
0 commit comments