Skip to content

Commit fbea2e0

Browse files
committed
ci:implement ci similar to decidim/decidim
1 parent 962b0fc commit fbea2e0

3 files changed

Lines changed: 182 additions & 128 deletions

File tree

.github/workflows/build_app.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
ruby_version:
5+
description: 'Ruby Version'
6+
default: "3.1.1"
7+
type: string
8+
required: false
9+
node_version:
10+
description: 'Node version'
11+
default: '18.17.1'
12+
required: false
13+
type: string
14+
jobs:
15+
build_app:
16+
name: Build app
17+
runs-on: ubuntu-22.04
18+
if: "!startsWith(github.head_ref, 'chore/l10n')"
19+
timeout-minutes: 60
20+
env:
21+
DATABASE_USERNAME: postgres
22+
DATABASE_PASSWORD: postgres
23+
DATABASE_HOST: localhost
24+
RUBYOPT: '-W:no-deprecated'
25+
services:
26+
postgres:
27+
image: postgres:14
28+
ports: ["5432:5432"]
29+
options: >-
30+
--health-cmd pg_isready
31+
--health-interval 10s
32+
--health-timeout 5s
33+
--health-retries 5
34+
env:
35+
POSTGRES_PASSWORD: postgres
36+
steps:
37+
- uses: actions/checkout@v3
38+
with:
39+
fetch-depth: 1
40+
- uses: ruby/setup-ruby@v1
41+
with:
42+
ruby-version: ${{ inputs.ruby_version }}
43+
bundler-cache: true
44+
- uses: actions/setup-node@v3
45+
with:
46+
node-version: ${{ inputs.node_version }}
47+
cache: 'npm'
48+
cache-dependency-path: ./package-lock.json
49+
- uses: actions/cache@v3
50+
id: app-cache
51+
with:
52+
path: ./spec/decidim_dummy_app/
53+
key: app-${{ github.sha }}
54+
restore-keys: app-${{ github.sha }}
55+
- run: bundle exec rake test_app
56+
name: Create test app
57+
shell: "bash"
58+
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
59+
name: Create the screenshots folder
60+
shell: "bash"
61+
- run: RAILS_ENV=test bundle exec rails assets:precompile
62+
name: Precompile assets
63+
working-directory: ./spec/decidim_dummy_app/
64+
shell: "bash"
65+
env:
66+
NODE_ENV: "test"

.github/workflows/ci_tests.yml

Lines changed: 17 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ env:
55
CI: "true"
66
RUBY_VERSION: 3.1.1
77
NODE_VERSION: 18.17.1
8-
CHROME_VERSION: 126.0.6478.182
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
11+
cancel-in-progress: true
912

1013
jobs:
14+
build_app:
15+
uses: ./.github/workflows/build_app.yml
16+
secrets: inherit
17+
name: Build test application
18+
1119
lint:
20+
name: Lint code
1221
runs-on: ubuntu-latest
22+
timeout-minutes: 60
1323
steps:
1424
- uses: actions/checkout@v3
1525
with:
@@ -25,132 +35,11 @@ jobs:
2535
name: Lint Ruby files
2636
- run: bundle exec erblint app/**/*.erb
2737
name: Lint ERB files
38+
2839
tests:
2940
name: Tests
30-
runs-on: ubuntu-latest
31-
timeout-minutes: 30
32-
services:
33-
postgres:
34-
image: postgres:11
35-
ports: ["5432:5432"]
36-
options: >-
37-
--health-cmd pg_isready
38-
--health-interval 10s
39-
--health-timeout 5s
40-
--health-retries 5
41-
env:
42-
POSTGRES_PASSWORD: postgres
43-
env:
44-
DATABASE_USERNAME: postgres
45-
DATABASE_PASSWORD: postgres
46-
DATABASE_HOST: localhost
47-
steps:
48-
- uses: rokroskar/workflow-run-cleanup-action@v0.3.0
49-
if: "github.ref != 'refs/heads/develop'"
50-
env:
51-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
52-
- uses: actions/checkout@v3
53-
with:
54-
fetch-depth: 1
55-
- uses: ruby/setup-ruby@v1
56-
with:
57-
bundler-cache: true
58-
- uses: actions/setup-node@v3
59-
with:
60-
node-version: ${{ env.NODE_VERSION }}
61-
- name: Get npm cache directory path
62-
id: npm-cache-dir-path
63-
run: echo "::set-output name=dir::$(npm get cache)-extra_user_fields"
64-
- uses: actions/cache@v3
65-
id: npm-cache
66-
with:
67-
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
68-
key: npm-${{ hashFiles('**/package-lock.json') }}
69-
restore-keys: |
70-
npm-
71-
- run: bundle exec rake test_app
72-
name: Create test app
73-
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
74-
name: Create the screenshots folder
75-
- uses: nanasess/setup-chromedriver@v2
76-
- run: RAILS_ENV=test bundle exec rails assets:precompile
77-
name: Precompile assets
78-
working-directory: ./spec/decidim_dummy_app/
79-
- run: bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb"
80-
name: RSpec
81-
- uses: codecov/codecov-action@v3
82-
- uses: actions/upload-artifact@v3
83-
if: always()
84-
with:
85-
name: screenshots
86-
path: ./spec/decidim_dummy_app/tmp/screenshots
87-
if-no-files-found: ignore
88-
system-tests:
89-
name: System tests
90-
runs-on: ubuntu-latest
91-
timeout-minutes: 30
92-
services:
93-
postgres:
94-
image: postgres:11
95-
ports: ["5432:5432"]
96-
options: >-
97-
--health-cmd pg_isready
98-
--health-interval 10s
99-
--health-timeout 5s
100-
--health-retries 5
101-
env:
102-
POSTGRES_PASSWORD: postgres
103-
env:
104-
DATABASE_USERNAME: postgres
105-
DATABASE_PASSWORD: postgres
106-
DATABASE_HOST: localhost
107-
steps:
108-
- uses: rokroskar/workflow-run-cleanup-action@v0.3.0
109-
if: "github.ref != 'refs/heads/develop'"
110-
env:
111-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
112-
- uses: actions/checkout@v3
113-
with:
114-
fetch-depth: 1
115-
- uses: ruby/setup-ruby@v1
116-
with:
117-
ruby-version: ${{ env.RUBY_VERSION }}
118-
bundler-cache: true
119-
- run: |
120-
sudo apt install libu2f-udev imagemagick
121-
wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{env.CHROME_VERSION}}-1_amd64.deb
122-
sudo dpkg -i /tmp/chrome.deb
123-
rm /tmp/chrome.deb
124-
name: Install Chrome version ${{ env.CHROME_VERSION }}
125-
- uses: actions/setup-node@v3
126-
with:
127-
node-version: ${{ env.NODE_VERSION }}
128-
- name: Get npm cache directory path
129-
id: npm-cache-dir-path
130-
run: echo "dir=$(npm get cache)--extra_user_fields" >> $GITHUB_OUTPUT
131-
- uses: actions/cache@v3
132-
id: npm-cache
133-
with:
134-
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
135-
key: npm-${{ hashFiles('**/package-lock.json') }}
136-
restore-keys: |
137-
npm-
138-
- run: bundle exec rake test_app
139-
name: Create test app
140-
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
141-
name: Create the screenshots folder
142-
- uses: nanasess/setup-chromedriver@v2
143-
with:
144-
chromedriver-version: ${{ env.CHROME_VERSION }}
145-
- run: RAILS_ENV=test bundle exec rails assets:precompile
146-
name: Precompile assets
147-
working-directory: ./spec/decidim_dummy_app/
148-
- run: bundle exec rspec spec/system
149-
name: RSpec
150-
- uses: codecov/codecov-action@v3
151-
- uses: actions/upload-artifact@v3
152-
if: always()
153-
with:
154-
name: screenshots
155-
path: ./spec/decidim_dummy_app/tmp/screenshots
156-
if-no-files-found: ignore
41+
needs: build_app.
42+
uses: ./.github/workflows/test_app.yml
43+
with:
44+
test_command: "bundle exec rspec --pattern './spec/**/*_spec.rb'"
45+
secrets: inherit

.github/workflows/test_app.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
ruby_version:
5+
description: 'Ruby Version'
6+
default: "3.1.1"
7+
required: false
8+
type: string
9+
test_command:
10+
description: 'The testing command to be ran'
11+
required: true
12+
type: string
13+
chrome_version:
14+
description: 'Chrome & Chromedriver version'
15+
required: false
16+
default: "126.0.6478.182"
17+
type: string
18+
19+
jobs:
20+
build_app:
21+
name: Test app
22+
runs-on: ubuntu-22.04
23+
if: "!startsWith(github.head_ref, 'chore/l10n')"
24+
timeout-minutes: 60
25+
env:
26+
DATABASE_USERNAME: postgres
27+
DATABASE_PASSWORD: postgres
28+
DATABASE_HOST: localhost
29+
RUBYOPT: '-W:no-deprecated'
30+
services:
31+
validator:
32+
image: ghcr.io/validator/validator:latest
33+
ports: ["8888:8888"]
34+
postgres:
35+
image: postgres:14
36+
ports: ["5432:5432"]
37+
options: >-
38+
--health-cmd pg_isready
39+
--health-interval 10s
40+
--health-timeout 5s
41+
--health-retries 5
42+
env:
43+
POSTGRES_PASSWORD: postgres
44+
steps:
45+
- uses: actions/checkout@v3
46+
with:
47+
fetch-depth: 1
48+
- uses: ruby/setup-ruby@v1
49+
with:
50+
ruby-version: ${{ inputs.ruby_version }}
51+
bundler-cache: true
52+
- run: |
53+
sudo apt update
54+
sudo apt install libu2f-udev
55+
wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{inputs.chrome_version}}-1_amd64.deb
56+
sudo dpkg -i /tmp/chrome.deb
57+
rm /tmp/chrome.deb
58+
- uses: nanasess/setup-chromedriver@v2
59+
name: Install Chrome version ${{inputs.chrome_version}}
60+
with:
61+
chromedriver-version: ${{inputs.chrome_version}}
62+
- uses: actions/cache@v3
63+
id: app-cache
64+
with:
65+
path: ./spec/decidim_dummy_app/
66+
key: app-${{ github.sha }}
67+
restore-keys: app-${{ github.sha }}
68+
- run: |
69+
bundle install
70+
bundle exec rake db:create db:schema:load
71+
name: Install gems and create db
72+
shell: "bash"
73+
working-directory: ./spec/decidim_dummy_app/
74+
- run: |
75+
sudo Xvfb -ac $DISPLAY -screen 0 1920x1084x24 > /dev/null 2>&1 &
76+
${{ inputs.test_command }}
77+
name: RSpec
78+
working-directory: ./
79+
env:
80+
VALIDATOR_HTML_URI: http://localhost:8888/
81+
RUBY_VERSION: ${{ inputs.ruby_version }}
82+
DECIDIM_MODULE: ${{ inputs.working-directory }}
83+
DISPLAY: ":99"
84+
CI: "true"
85+
SIMPLECOV: "true"
86+
SHAKAPACKER_RUNTIME_COMPILE: "false"
87+
NODE_ENV: "test"
88+
- uses: codecov/codecov-action@v3
89+
name: Upload coverage
90+
with:
91+
name: ${{ inputs.working-directory }}
92+
flags: ${{ inputs.working-directory }}
93+
- uses: actions/upload-artifact@v3
94+
if: always()
95+
with:
96+
name: screenshots
97+
path: ./spec/decidim_dummy_app/tmp/screenshots
98+
if-no-files-found: ignore
99+
overwrite: true

0 commit comments

Comments
 (0)