Skip to content

Commit 03d8a7d

Browse files
Merge pull request #130 from puppetlabs/OSPTE-186
Add PuppetCore gem source support to gem_ci and tools_mend_ruby workflows
2 parents 28ec60f + 1535f3d commit 03d8a7d

5 files changed

+99
-115
lines changed

Diff for: .github/workflows/gem_ci.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,20 @@ on:
3030
default: false
3131
type: "boolean"
3232

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_GEM_VERSION: ${{ inputs.puppet_gem_version }}
38+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
40+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
41+
3342
jobs:
3443
spec:
3544
name: "spec"
3645
runs-on: ${{ inputs.runs_on }}
3746

38-
env:
39-
PUPPET_GEM_VERSION: ${{ inputs.puppet_gem_version }}
40-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
41-
4247
steps:
4348
- name: "checkout"
4449
uses: "actions/checkout@v4"

Diff for: .github/workflows/module_ci.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ on:
2424
required: false
2525
default: '3.1'
2626
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"
3227

3328
# ENABLE PUPPETCORE. The calling workflow must:
3429
# - Set a valid PUPPET_FORGE_TOKEN secret on its repository.
3530
# - Set ruby_version >= 3.1 to override this workflow's default 2.7; otherwise bundle install will fail.
3631
env:
3732
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
38-
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "${{ inputs.puppetcore_api_type }}:${{ secrets.PUPPET_FORGE_TOKEN }}"
33+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
3934

4035
jobs:
4136
setup_matrix:

Diff for: .github/workflows/tooling_mend_ruby.yml

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ env:
2525
MEND_TOKEN: ${{ secrets.MEND_TOKEN != '' && secrets.MEND_TOKEN || inputs.token }}
2626
PRODUCT_NAME: ${{ inputs.PRODUCT_NAME != '' && inputs.PRODUCT_NAME || inputs.product_name }}
2727
REQUIRE_SECRETS: MEND_API_KEY MEND_TOKEN
28+
# ENABLE PUPPETCORE. The calling workflow must:
29+
# - Set a valid PUPPET_FORGE_TOKEN secret on its repository.
30+
# - Set ruby_version >= 3.1 to override this workflow's default 2.7; otherwise bundle install will fail.
31+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
32+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
2833

2934
jobs:
3035
mend:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# How to inject puppetcore authentication into the shared workflows
2+
3+
## Description
4+
5+
This guide explains how to configure your repository to consume the following shared workflows and ensure that puppetcore dependencies are successfully bundle installed:
6+
7+
- `module_ci.yml`
8+
- `gem_ci.yml`
9+
- `tooling_mend_ruby.yml`
10+
11+
The above workflows are backward compatible and designed to work with both puppetcore and non-puppetcore repositories.
12+
13+
## Prerequisites
14+
15+
- A puppetcore repository that needs to use a shared workflow.
16+
- Access to repository settings to configure secrets
17+
- A valid `PUPPET_FORGE_TOKEN` with access to the private puppetcore gem source
18+
19+
## Configuration Requirements
20+
21+
### Required Settings
22+
23+
To use PuppetCore Gems with the above shared workflows, your repository must meet these requirements:
24+
25+
1. **Set up the PUPPET_FORGE_TOKEN secret**:
26+
- Navigate to your repository on GitHub
27+
- Go to Settings > Secrets and variables > Actions
28+
- Add a new repository secret named `PUPPET_FORGE_TOKEN` with your valid token value
29+
30+
2. **Configure Ruby Version to be >= 3.1**:
31+
- Ruby version >= 3.1 is required for PuppetCore Gems.
32+
- Some shared worklows, like `module_ci.yml`, have an old default Ruby version that must be overridden
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+
For 2 example consumers, see:
57+
58+
* [puppet-upgrade ci.yml](https://github.com/puppetlabs/puppet-upgrade/blob/main/.github/workflows/ci.yml)
59+
* [provision ci.yml](https://github.com/puppetlabs/provision/blob/main/.github/workflows/ci.yml)
60+
61+
## How It Works
62+
63+
The above shared workflows are designed to install gems from <https://rubygems-puppetcore.puppet.com>. They
64+
65+
- **Inherit** the `PUPPET_FORGE_TOKEN` secret from the consumer repository and then **set** an environment variable of the same name. This environment variable is required by some repositories to "switch" between either the public or puppetcore gems.
66+
- **Set** the `BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM` environment variable ensuring authentication against the <https://rubygems-puppetcore.puppet.com> gemsource. For example,
67+
68+
```bash
69+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
70+
```
71+
72+
## Troubleshooting
73+
74+
Common issues and their solutions:
75+
76+
- **Bundle install fails**: Ensure Ruby version is set to at least 3.1
77+
- **Authentication errors**: Verify the PUPPET_FORGE_TOKEN is correctly set and has appropriate permissions
78+
79+
## Appendix
80+
81+
### Security Considerations
82+
83+
- Use the `secrets: "inherit"` pattern to securely pass tokens from your consumer to shared workflow.
84+
- Push secrets into environment variables for use by code. This is another github pattern that maintains redaction of secrets in logs

Diff for: docs/how-to/how_to_using_module_ci_workflow_with_puppetcore_gems.md

-105
This file was deleted.

0 commit comments

Comments
 (0)