Skip to content

Commit 797990d

Browse files
Use GitHub-owned actions and browser fallback scripts
Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
1 parent 3332fcb commit 797990d

2 files changed

Lines changed: 58 additions & 36 deletions

File tree

.github/workflows/ci.yml

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,35 @@ jobs:
1616
lint:
1717
runs-on: ubuntu-latest
1818
timeout-minutes: 20
19+
container:
20+
image: ruby:3.4
1921

2022
steps:
2123
- uses: actions/checkout@v4
2224

2325
- name: Install lint dependencies
24-
run: sudo apt-get update && sudo apt-get install --yes --no-install-recommends libpq-dev
25-
26-
- name: Set up Ruby
27-
uses: ruby/setup-ruby@v1
28-
with:
29-
ruby-version: .tool-versions
30-
bundler-cache: true
26+
run: apt-get update && apt-get install --yes --no-install-recommends build-essential git libpq-dev pkg-config
3127

3228
- name: Run RuboCop
33-
run: bundle exec rubocop --format progress
29+
run: bundle install && bundle exec rubocop --format progress
3430

3531
test:
3632
runs-on: ubuntu-latest
3733
timeout-minutes: 45
34+
container:
35+
image: ruby:3.4
3836
permissions:
3937
contents: read
38+
issues: write
4039
pull-requests: write
4140
env:
4241
RAILS_ENV: test
4342
POSTGRES_DB: choco_cake_test
4443
POSTGRES_PASSWORD: password
4544
POSTGRES_USER: choco
46-
POSTGRES_HOST: 127.0.0.1
45+
POSTGRES_HOST: postgres
4746
POSTGRES_PORT: '5432'
48-
REDIS_URL: redis://127.0.0.1:6379/1
47+
REDIS_URL: redis://redis:6379/1
4948
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: primary-key
5049
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: deterministic-key
5150
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: derivation-salt
@@ -57,47 +56,36 @@ jobs:
5756
POSTGRES_DB: choco_cake_test
5857
POSTGRES_PASSWORD: password
5958
POSTGRES_USER: choco
60-
ports:
61-
- 5432:5432
6259
options: >-
6360
--health-cmd="pg_isready -U choco -d choco_cake_test"
6461
--health-interval=10s
6562
--health-timeout=5s
6663
--health-retries=5
6764
redis:
6865
image: redis:6.2-alpine
69-
ports:
70-
- 6379:6379
7166

7267
steps:
7368
- uses: actions/checkout@v4
7469

7570
- name: Install test dependencies
76-
run: sudo apt-get update && sudo apt-get install --yes --no-install-recommends libpq-dev postgresql-client jq curl imagemagick
77-
78-
- name: Set up Ruby
79-
uses: ruby/setup-ruby@v1
80-
with:
81-
ruby-version: .tool-versions
82-
bundler-cache: true
83-
84-
- name: Set up Firefox
85-
id: setup_firefox
86-
continue-on-error: true
87-
uses: browser-actions/setup-firefox@v1
88-
89-
- name: Set up Chrome fallback
90-
if: steps.setup_firefox.outcome == 'failure'
91-
uses: browser-actions/setup-chrome@v1
71+
run: >
72+
apt-get update && apt-get install --yes --no-install-recommends
73+
build-essential git libpq-dev pkg-config postgresql-client jq curl imagemagick firefox-esr chromium
9274
9375
- name: Select system test browser
9476
run: |
95-
if [ "${{ steps.setup_firefox.outcome }}" = "success" ]; then
77+
if command -v firefox >/dev/null 2>&1; then
9678
echo "SYSTEM_TEST_BROWSER=firefox" >> "$GITHUB_ENV"
9779
echo "Using Firefox for system tests"
9880
else
81+
echo "Firefox unavailable; falling back to Chrome"
9982
echo "SYSTEM_TEST_BROWSER=chrome" >> "$GITHUB_ENV"
100-
echo "Falling back to Chrome for system tests"
83+
chrome_bin="$(command -v google-chrome || command -v chromium || command -v chromium-browser || true)"
84+
if [ -z "$chrome_bin" ]; then
85+
echo "Chrome fallback requested, but no Chrome binary is available"
86+
exit 1
87+
fi
88+
echo "CHROME_BIN=$chrome_bin" >> "$GITHUB_ENV"
10189
fi
10290
10391
- name: Wait for DB
@@ -106,6 +94,9 @@ jobs:
10694
sleep 1
10795
done
10896
97+
- name: Install gems
98+
run: bundle install
99+
109100
- name: Database setup
110101
run: bin/rails db:setup --trace
111102

@@ -153,8 +144,38 @@ Run: $run_url"
153144

154145
- name: Comment coverage on PR
155146
if: always() && github.event_name == 'pull_request'
156-
continue-on-error: true
157-
uses: marocchino/sticky-pull-request-comment@v2
147+
uses: actions/github-script@v7
148+
env:
149+
COVERAGE_MESSAGE: ${{ steps.coverage_comment.outputs.message }}
158150
with:
159-
header: simplecov-coverage
160-
message: ${{ steps.coverage_comment.outputs.message }}
151+
script: |
152+
const marker = '<!-- simplecov-coverage -->';
153+
const body = `${marker}\n${process.env.COVERAGE_MESSAGE}`;
154+
const issue_number = context.payload.pull_request.number;
155+
156+
const { data: comments } = await github.rest.issues.listComments({
157+
owner: context.repo.owner,
158+
repo: context.repo.repo,
159+
issue_number,
160+
per_page: 100
161+
});
162+
163+
const existing = comments.find((comment) =>
164+
comment.user?.type === 'Bot' && comment.body?.includes(marker)
165+
);
166+
167+
if (existing) {
168+
await github.rest.issues.updateComment({
169+
owner: context.repo.owner,
170+
repo: context.repo.repo,
171+
comment_id: existing.id,
172+
body
173+
});
174+
} else {
175+
await github.rest.issues.createComment({
176+
owner: context.repo.owner,
177+
repo: context.repo.repo,
178+
issue_number,
179+
body
180+
});
181+
}

spec/rails_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
Webdrivers::Geckodriver.update
129129
driven_by :selenium_headless, using: :firefox
130130
when 'chrome'
131+
Selenium::WebDriver::Chrome.path = ENV['CHROME_BIN'] if ENV['CHROME_BIN']
131132
Webdrivers::Chromedriver.update
132133
driven_by :selenium_headless, using: :chrome
133134
else

0 commit comments

Comments
 (0)