Skip to content

Commit d8097ee

Browse files
authored
chore: configure CI like openfoodfacts (#59)
1 parent 73eae10 commit d8097ee

12 files changed

+232
-54
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# review when someone opens a pull request.
44
# For more on how to customize the CODEOWNERS file - https://help.github.com/en/articles/about-code-owners
55

6-
* @openfoodfacts/openfoodfacts-ruby
6+
* @openfoodfacts/openbeautyfacts-ruby

.github/copilot-instructions.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# OpenBeautyFacts Ruby SDK
2+
3+
OpenBeautyFacts Ruby SDK is a Ruby gem that provides API access to the Open Food Facts database, the open database about food. The gem includes models for Product, Locale, User and many other food-related entities.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Environment Setup
10+
- Install Ruby 2.5 or higher (project supports Ruby 2.5-3.3, current development uses Ruby 3.3.6)
11+
- Install Bundler for dependency management:
12+
```bash
13+
gem install bundler --user-install
14+
export PATH="$PATH:$HOME/.local/share/gem/ruby/3.2.0/bin"
15+
```
16+
- Configure Bundler to install gems to user directory:
17+
```bash
18+
bundle config path ~/.gems
19+
```
20+
21+
### Bootstrap, Build, and Test
22+
- **Install dependencies**: `bundle install` -- takes 5-15 seconds. NEVER CANCEL. Set timeout to 60+ seconds.
23+
- **Run tests**: `bundle exec rake test` -- takes 2-3 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
24+
- NOTE: Tests may have failures due to external API dependencies being unreachable in restricted environments
25+
- **Build gem**: `bundle exec rake build` -- takes 1 second. NEVER CANCEL. Set timeout to 30+ seconds.
26+
- **Install gem locally**: `bundle exec rake install:local` -- takes 1-2 seconds.
27+
28+
### Development Commands
29+
- **List all rake tasks**: `bundle exec rake -T`
30+
- **Launch console**: `bundle exec rake console` (may hang, use `bundle exec irb -r openbeautyfacts` instead)
31+
- **Clean build artifacts**: `bundle exec rake clobber`
32+
33+
## Validation
34+
35+
### Always Test Core Functionality
36+
After making changes, always validate by running:
37+
```ruby
38+
# Create a test script to verify basic functionality
39+
require 'openbeautyfacts'
40+
puts "Version: #{Openbeautyfacts::VERSION}"
41+
product = Openbeautyfacts::Product.new(code: "test")
42+
puts "Product URL: #{Openbeautyfacts::Product.url('test', locale: 'world')}"
43+
```
44+
45+
### Linting
46+
- RuboCop is used for code style but is not included in development dependencies
47+
- Install and run manually:
48+
```bash
49+
gem install rubocop --user-install
50+
rubocop lib/openbeautyfacts.rb
51+
```
52+
- CI pipeline includes RuboCop analysis (see `.github/workflows/rubocop-analysis.yml`)
53+
54+
### Manual Testing Scenarios
55+
- Always test that the library loads: `require 'openbeautyfacts'`
56+
- Verify version access: `Openbeautyfacts::VERSION` should return current version (0.6.2)
57+
- Test Product model instantiation: `Openbeautyfacts::Product.new(code: "test")`
58+
- Verify URL generation: `Openbeautyfacts::Product.url("123", locale: "world")`
59+
60+
## Common Tasks
61+
62+
### Repo Structure
63+
```
64+
.
65+
├── .github/ # GitHub workflows and configs
66+
├── lib/
67+
│ ├── openbeautyfacts.rb # Main module file
68+
│ └── openbeautyfacts/
69+
│ ├── product.rb # Core Product model
70+
│ ├── locale.rb # Locale handling
71+
│ ├── user.rb # User authentication
72+
│ └── [27 other models] # Brand, Category, etc.
73+
├── test/
74+
│ ├── minitest_helper.rb # Test configuration
75+
│ ├── test_openbeautyfacts.rb # Main test file
76+
│ └── fixtures/ # VCR test fixtures
77+
├── Gemfile # Dependencies
78+
├── openbeautyfacts.gemspec # Gem specification
79+
├── Rakefile # Build tasks
80+
└── README.md # Usage documentation
81+
```
82+
83+
### Key Files to Know
84+
- **Main entry point**: `lib/openbeautyfacts.rb` - defines module and requires all classes
85+
- **Primary model**: `lib/openbeautyfacts/product.rb` - core Product class with API methods
86+
- **Version**: `lib/openbeautyfacts/version.rb` - contains `VERSION = "0.6.2"`
87+
- **Tests**: `test/test_openbeautyfacts.rb` - comprehensive test suite with VCR fixtures
88+
- **CI workflows**:
89+
- `.github/workflows/ruby.yml` - runs tests on Ruby 2.5-3.3
90+
- `.github/workflows/rubocop-analysis.yml` - static code analysis
91+
92+
### Dependencies
93+
- **Runtime**: `hashie` (>= 3.4, < 6.0), `nokogiri` (~> 1.7)
94+
- **Development**: `minitest`, `vcr`, `webmock`, `rake`, `bundler`
95+
- **Ruby requirement**: >= 2.5
96+
97+
### API and Network Dependencies
98+
- The gem connects to `openbeautyfacts.org` for live data
99+
- Tests use VCR (Video Cassette Recorder) to mock HTTP requests
100+
- In network-restricted environments, only basic functionality (class loading, URL generation) can be tested
101+
- Real API calls require setting `OPENBEAUTYFACTS_USER_AGENT` environment variable
102+
103+
### Common Issues
104+
- **Permission errors during gem install**: Use `--user-install` flag and update PATH
105+
- **Bundle install fails**: Configure `bundle config path ~/.gems` first
106+
- **Test failures**: Expected when network access is restricted; focus on gem build success
107+
- **RuboCop not found**: Install separately with `gem install rubocop --user-install`
108+
109+
### Development Workflow
110+
1. Make changes to lib/ files
111+
2. Run `bundle exec rake build` to verify gem builds
112+
3. Run `bundle exec rake test` to run test suite
113+
4. Create simple validation script to test core functionality
114+
5. Run RuboCop for style checking (if installed)
115+
6. Always test that the gem loads and basic models work
116+
117+
This gem provides a Ruby interface to the Open Food Facts database with models for products, locales, users, and food-related metadata. Changes should maintain backward compatibility and follow the existing patterns in the codebase.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# .github/workflows/auto-author-assign.yml
2+
name: 'Auto Author Assign'
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, reopened]
7+
8+
permissions:
9+
pull-requests: write
10+
11+
jobs:
12+
assign-author:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: toshimaru/auto-author-assign@v2.1.1

.github/workflows/github-projects.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
name: Ventilate issues to the right GitHub openbeautyfacts project
1+
name: Add bugs to the relevant GitHub Projects
22

33
on:
44
issues:
55
types:
66
- opened
77
- labeled
8-
- transfered
8+
- transferred
9+
10+
permissions:
11+
issues: read
12+
repository-projects: write
913

1014
jobs:
11-
add-to-projects:
12-
name: Ventilate issues to the right GitHub projects
13-
runs-on: ubuntu-latest
14-
steps:
15-
- uses: actions/add-to-project@main
16-
with:
17-
project-url: https://github.com/orgs/openfoodfacts/projects/37 # Add issue to the openbeautyfacts project
18-
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
1915
add-to-design-project:
2016
name: 🎨 Add issue to the openfoodfacts-design project
2117
runs-on: ubuntu-latest

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish gem on Rubygems
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [created]
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
environment: release
16+
steps:
17+
- uses: actions/checkout@v5
18+
with: # Load existing tags to avoid duplicate tag error
19+
fetch-depth: 0
20+
fetch-tags: true
21+
- uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: ${{ vars.RUBY_VERSION }}
24+
bundler-cache: true
25+
- name: Build gem
26+
run: gem build *.gemspec
27+
- name: Publish gem
28+
uses: rubygems/release-gem@v1
Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
1-
name: Run release-please
2-
on:
3-
push:
4-
branches:
5-
- main
6-
jobs:
7-
release-please:
8-
runs-on: ubuntu-latest
9-
steps:
10-
- uses: GoogleCloudPlatform/release-please-action@v4
11-
id: release
12-
with:
13-
token: ${{ secrets.GITHUB_TOKEN }}
14-
release-type: ruby
15-
package-name: openbeautyfacts
16-
version-file: "lib/openbeautyfacts/version.rb"
17-
# Checkout code if release was created
18-
- uses: actions/checkout@v5
19-
if: ${{ steps.release.outputs.release_created }}
20-
# Setup ruby if a release was created
21-
- uses: ruby/setup-ruby@v1
22-
with:
23-
ruby-version: 3.0.0
24-
if: ${{ steps.release.outputs.release_created }}
25-
# Bundle install
26-
- run: bundle install
27-
if: ${{ steps.release.outputs.release_created }}
28-
# Publish
29-
- name: publish gem
30-
run: |
31-
mkdir -p $HOME/.gem
32-
touch $HOME/.gem/credentials
33-
chmod 0600 $HOME/.gem/credentials
34-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
35-
gem build *.gemspec
36-
gem push *.gem
37-
env:
38-
# Make sure to update the secret name
39-
# if yours isn't named RUBYGEMS_AUTH_TOKEN
40-
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
41-
if: ${{ steps.release.outputs.release_created }}
1+
name: Run release-please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
id-token: write
11+
pull-requests: write
12+
13+
jobs:
14+
release-please:
15+
runs-on: ubuntu-latest
16+
env:
17+
GEM_NAME: openbeautyfacts
18+
steps:
19+
- uses: GoogleCloudPlatform/release-please-action@v4
20+
id: release
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
release-type: ruby
24+
include-component-in-tag: false

.github/workflows/rubocop-analysis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: "RuboCop"
22

33
on: [push]
44

5+
permissions:
6+
contents: read
7+
security-events: write
8+
59
jobs:
610
rubocop:
711
runs-on: ubuntu-latest
@@ -15,7 +19,7 @@ jobs:
1519
- name: Set up Ruby
1620
uses: ruby/setup-ruby@v1
1721
with:
18-
ruby-version: 2.6
22+
ruby-version: ${{ vars.RUBY_VERSION }}
1923

2024
# This step is not necessary if you add the gem to your Gemfile
2125
- name: Install Code Scanning integration

.github/workflows/ruby.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
test:
1114

1215
runs-on: ubuntu-latest
1316
strategy:
1417
fail-fast: false
1518
matrix:
16-
ruby: [2.5, 2.6, 2.7, 3.0]
19+
ruby: [3.2, 3.3, 3.4]
1720

1821
steps:
1922
- uses: actions/checkout@v5

.github/workflows/semantic-pr.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Semantic PRs"
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
permissions:
11+
pull-requests: read
12+
13+
jobs:
14+
main:
15+
name: Validate PR title
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: amannn/action-semantic-pull-request@v6
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.10.0"
3+
}

0 commit comments

Comments
 (0)