Skip to content

Commit 2513c6c

Browse files
authored
Merge pull request #129 from puppetlabs/puppetcore
Add PuppetCore gem source support to module_ci workflow
2 parents cb81a0b + 05d7526 commit 2513c6c

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

Diff for: .github/workflows/module_ci.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ on:
1919
required: false
2020
default: false
2121
type: "boolean"
22+
ruby_version:
23+
description: "Ruby version to use"
24+
required: false
25+
default: '2.7'
26+
type: "string"
27+
puppetcore_api_type:
28+
description: "The type of API to use for Puppet Core."
29+
required: false
30+
default: 'forge-key'
31+
type: "string"
2232

33+
# ENABLE PUPPETCORE. The calling workflow must:
34+
# - Set a valid PUPPET_FORGE_TOKEN secret on its repository.
35+
# - Set ruby_version >= 3.1 to override this workflow's default 2.7; otherwise bundle install will fail.
36+
env:
37+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
38+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "${{ inputs.puppetcore_api_type }}:${{ secrets.PUPPET_FORGE_TOKEN }}"
2339

2440
jobs:
2541
setup_matrix:
@@ -41,7 +57,7 @@ jobs:
4157
- name: "Setup ruby"
4258
uses: "ruby/setup-ruby@v1"
4359
with:
44-
ruby-version: "2.7"
60+
ruby-version: ${{ inputs.ruby_version }}
4561
bundler-cache: true
4662

4763
- name: "Bundle environment"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# How to use the module_ci workflow with puppetcore gems
2+
3+
## Description
4+
5+
This guide explains how to configure your repository to use the shared `module_ci.yml` workflow with PuppetCore Gems. The workflow is designed to maintain backward compatibility with existing consumers (like puppetlabs-apache and puppetlabs-ntp) while providing the capability to install and use gems from the private PuppetCore gem source.
6+
7+
## Prerequisites
8+
9+
- A GitHub repository that needs to use the `module_ci.yml` workflow
10+
- Access to repository settings to configure secrets
11+
- A valid `PUPPET_FORGE_TOKEN` with access to the private gem source
12+
13+
## Configuration Requirements
14+
15+
### Required Settings
16+
17+
To use PuppetCore Gems with the module_ci workflow, your repository must meet these requirements:
18+
19+
1. **Set up the PUPPET_FORGE_TOKEN secret**:
20+
- Navigate to your repository on GitHub
21+
- Go to Settings > Secrets and variables > Actions
22+
- Add a new repository secret named `PUPPET_FORGE_TOKEN` with your valid token value
23+
24+
2. **Configure Ruby Version**:
25+
- Must specify a Ruby version >= 3.1 (required for PuppetCore Gems)
26+
- The default Ruby version in module_ci.yml is 2.7 and must be overridden
27+
28+
### Optional Settings
29+
30+
- **PuppetCore API Type**:
31+
- By default, set to 'forge-key'
32+
- Can be changed to 'license-key' if required
33+
34+
## Usage
35+
36+
Create or update your workflow file (typically `.github/workflows/ci.yml`) to look something like:
37+
38+
```yaml
39+
name: "ci"
40+
41+
on:
42+
pull_request:
43+
branches:
44+
- "main"
45+
workflow_dispatch:
46+
47+
jobs:
48+
Spec:
49+
uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main"
50+
with:
51+
run_shellcheck: true
52+
ruby_version: '3.1' # Required for PuppetCore Gems
53+
secrets: "inherit" # Required to pass PUPPET_FORGE_TOKEN
54+
```
55+
56+
## How It Works
57+
58+
When properly configured, the `module_ci.yml` workflow will:
59+
60+
1. Inherit the `PUPPET_FORGE_TOKEN` secret from the consumer repository.
61+
2. Set the following `BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM` environment variable ensuring authentication against the <https://rubygems-puppetcore.puppet.com> gemsource, e.g,:
62+
63+
```shell
64+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
65+
```
66+
67+
3. Install gems from <https://rubygems-puppetcore.puppet.com>.
68+
69+
## Troubleshooting
70+
71+
Common issues and their solutions:
72+
73+
- **Bundle install fails**: Ensure Ruby version is set to at least 3.1
74+
- **Authentication errors**: Verify the PUPPET_FORGE_TOKEN is correctly set and has appropriate permissions
75+
76+
## Appendix
77+
78+
### Sample Implementation
79+
80+
Example configuration in a consuming repository:
81+
82+
```yaml
83+
name: "ci"
84+
85+
on:
86+
pull_request:
87+
branches:
88+
- "main"
89+
workflow_dispatch:
90+
91+
jobs:
92+
Spec:
93+
uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main"
94+
with:
95+
run_shellcheck: true
96+
ruby_version: '3.1'
97+
puppetcore_api_type: 'license-key'
98+
secrets: "inherit"
99+
```
100+
101+
### Security Considerations
102+
103+
- Never hardcode the PUPPET_FORGE_TOKEN in your workflow files
104+
- Use the `secrets: "inherit"` pattern to securely pass tokens
105+
- Regularly rotate your tokens following security best practices

0 commit comments

Comments
 (0)