|
| 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