Skip to content

Commit ab55efe

Browse files
authored
Semaphore demo Rspec tests
1 parent 9a19429 commit ab55efe

1 file changed

Lines changed: 127 additions & 67 deletions

File tree

.semaphore/semaphore.yml

Lines changed: 127 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,163 @@
11
version: v1.0
2-
name: Semaphore React Native iOS Example Pipeline
2+
name: "💎 Ruby CI Pipeline (demo safe)"
3+
4+
# ---------------------------------------------------------------------
5+
# GLOBAL SETTINGS
6+
# ---------------------------------------------------------------------
37
agent:
48
machine:
5-
type: e1-standard-2
6-
os_image: ubuntu2004
7-
containers:
8-
- name: main
9-
image: 'registry.semaphoreci.com/android:34-node'
9+
type: f1-standard-2
10+
os_image: ubuntu2404
11+
1012
fail_fast:
1113
stop:
12-
when: branch != 'master'
14+
when: branch != 'main'
1315
auto_cancel:
1416
running:
15-
when: branch != 'master'
17+
when: branch != 'main'
1618
queued:
17-
when: branch = 'master'
19+
when: branch = 'main'
20+
21+
# Common pre-steps for every job
1822
global_job_config:
1923
prologue:
2024
commands:
21-
- checkout
22-
- cache restore
25+
# Helper: run a command, or sleep N seconds and pass
26+
- |
27+
run_or_pass() {
28+
echo "→ $*"
29+
eval "$@"
30+
rc=$?
31+
if [ $rc -ne 0 ]; then
32+
echo "[demo] Command failed (rc=$rc). Sleeping ${SLEEP_SEC:-12}s and marking as success."
33+
sleep "${SLEEP_SEC:-12}"
34+
return 0
35+
fi
36+
return 0
37+
}
38+
- export SLEEP_SEC="${SLEEP_SEC:-12}"
39+
40+
# Usual setup, protected by run_or_pass
41+
- run_or_pass checkout
42+
- run_or_pass "sem-service start postgres 17"
43+
- run_or_pass "sem-service start redis 7"
44+
- run_or_pass "sem-version ruby 3.2.2"
45+
- run_or_pass "sem-version node 20.11.0"
46+
- run_or_pass "cache restore"
47+
48+
# ---------------------------------------------------------------------
49+
# WORKFLOW
50+
# ---------------------------------------------------------------------
2351
blocks:
24-
- name: "\U0001F4E6 Install Dependencies"
52+
# ---------------- SETUP ----------------
53+
- name: "🛠 Setup & Cache"
54+
task:
55+
jobs:
56+
- name: Install Gems & JS deps
57+
commands:
58+
- run_or_pass "yarn --version"
59+
- run_or_pass "yarn install --frozen-lockfile"
60+
- run_or_pass "bundle --version"
61+
- run_or_pass "bundle install --deployment --path vendor/bundle"
62+
- run_or_pass "gem install --no-document semaphore_test_boosters"
63+
- run_or_pass "cache store"
2564
dependencies: []
65+
66+
# ------------- FRONT-END BUILD -------------
67+
- name: "🖼️ Webpacker Build"
2668
task:
2769
jobs:
28-
- name: "\U0001F4C2 npm install and cache"
70+
- name: Compile Assets
2971
commands:
30-
- npm install
31-
- cache store
32-
- name: "\U0001F50D Run Linter"
72+
- run_or_pass "cache restore webpacker-assets"
73+
- run_or_pass "bundle exec rake webpacker:compile"
74+
- run_or_pass "cache store webpacker-assets public/packs"
3375
dependencies:
34-
- "\U0001F4E6 Install Dependencies"
76+
- "🛠 Setup & Cache"
77+
78+
# ------------- CODE QUALITY -------------
79+
- name: "🔍 ESLint & Stylelint"
3580
task:
3681
jobs:
37-
- name: "\U0001F9F9 Run ESLint"
82+
- name: JS / CSS Lint
3883
commands:
39-
- npm run lint
40-
- name: "\U0001F9EA iOS Unit and Integration Tests"
84+
- run_or_pass "yarn run eslint ."
85+
- run_or_pass "yarn run stylelint '**/*.scss'"
4186
dependencies:
42-
- "\U0001F50D Run Linter"
87+
- "🖼️ Webpacker Build"
88+
89+
- name: "🧹 RuboCop"
4390
task:
44-
agent:
45-
machine:
46-
type: a2-standard-4
47-
os_image: macos-xcode16
4891
jobs:
49-
- name: ✅ iOS Unit and Integration Tests
50-
parallelism: 2
92+
- name: Ruby Style Check
5193
commands:
52-
- npm test
53-
- name: "\U0001F9EA iOS E2E Tests"
94+
- run_or_pass "bundle exec rubocop"
5495
dependencies:
55-
- "\U0001F50D Run Linter"
96+
- "🛠 Setup & Cache"
97+
98+
# ------------- SECURITY -------------
99+
- name: "🛡️ Brakeman"
56100
task:
57-
agent:
58-
machine:
59-
type: a2-standard-4
60-
os_image: macos-xcode16
61101
jobs:
62-
- name: "\U0001F3AD iOS E2E Tests"
63-
parallelism: 2
102+
- name: Static Analysis
64103
commands:
65-
- brew tap wix/brew
66-
- brew install applesimutils
67-
- nvm install 14
68-
- cd ios && pod install && cd ..
69-
- npm run detox-clean-and-build-cache
70-
- npm run detox-ios-build-release
71-
- npm run detox-ios-test-release
72-
- artifact push workflow ios/build/Build/Products/Release-iphonesimulator/ReactNativeSemaphoreNew.app
73-
- name: "\U0001F9EA Android Unit and Integration Tests"
104+
- run_or_pass "bundle exec brakeman --force"
74105
dependencies:
75-
- "\U0001F50D Run Linter"
106+
- "🛠 Setup & Cache"
107+
108+
- name: "🛡️ Bundler Audit"
76109
task:
77-
prologue:
78-
commands:
79-
- sdkmanager "platform-tools" "platforms;android-24" "emulator"
80-
- sdkmanager "system-images;android-24;default;x86"
81-
- echo no | avdmanager create avd -n Nexus_S_API_24 -k "system-images;android-24;default;x86" --device "Nexus S"
82110
jobs:
83-
- name: ✅ Android Unit and Integration Tests
84-
parallelism: 2
111+
- name: Gem CVE Check
85112
commands:
86-
- npm test
87-
- name: "\U0001F9EA Android E2E Tests"
113+
- run_or_pass "bundle exec bundle-audit check --update"
88114
dependencies:
89-
- "\U0001F50D Run Linter"
115+
- "🛠 Setup & Cache"
116+
117+
# ------------- TEST SUITE (Boosters) -------------
118+
- name: "🚦 RSpec Suite"
90119
task:
91-
prologue:
92-
commands:
93-
- sdkmanager "platform-tools" "platforms;android-24" "emulator"
94-
- sdkmanager "system-images;android-24;default;x86"
95-
- echo no | avdmanager create avd -n Nexus_S_API_24 -k "system-images;android-24;default;x86" --device "Nexus S"
120+
env_vars:
121+
- name: RAILS_ENV
122+
value: test
123+
- name: PGHOST
124+
value: 127.0.0.1
125+
- name: PGUSER
126+
value: postgres
96127
jobs:
97-
- name: "\U0001F3AD Android E2E Tests"
98-
parallelism: 2
128+
- name: "🟢 RSpec Tests"
129+
parallelism: 5
130+
commands:
131+
- run_or_pass "cache restore webpacker-assets"
132+
- run_or_pass "bundle exec rake db:setup"
133+
# Try to run split tests with Boosters; if unavailable, sleep and pass
134+
- run_or_pass 'rspec_booster --job "$SEMAPHORE_JOB_INDEX/$SEMAPHORE_JOB_COUNT" --format RspecJunitFormatter --out report.xml --format documentation'
135+
# If no JUnit got produced, create a tiny dummy so report steps don't fail
136+
- |
137+
if [ ! -f report.xml ]; then
138+
echo '[demo] Creating dummy JUnit report.xml'
139+
cat > report.xml <<'XML'
140+
<testsuite name="demo" tests="1" failures="0" errors="0" time="0.0">
141+
<testcase classname="demo" name="placeholder"/>
142+
</testsuite>
143+
XML
144+
fi
145+
epilogue:
146+
always:
99147
commands:
100-
- npm run detox-clean-and-build-cache
101-
- npm run detox-android-build-release
102-
- npm run detox-android-test-release
103-
- artifact push workflow android/app/build/outputs/apk/release/app-release.apk
148+
- run_or_pass 'test -f report.xml && test-results publish report.xml'
149+
dependencies:
150+
- "🧹 RuboCop"
151+
- "🛡️ Brakeman"
152+
- "🛡️ Bundler Audit"
153+
- "🖼️ Webpacker Build"
154+
155+
# ---------------------------------------------------------------------
156+
# PIPELINE SUMMARY
157+
# ---------------------------------------------------------------------
158+
after_pipeline:
159+
task:
160+
jobs:
161+
- name: "📊 Merge Results"
162+
commands:
163+
- run_or_pass "test-results gen-pipeline-report"

0 commit comments

Comments
 (0)