Skip to content

Commit c6846b6

Browse files
committed
Rewrite github actions to use reusable workflows
Also use docker image on staging deploy
1 parent 1b52d2d commit c6846b6

File tree

11 files changed

+230
-280
lines changed

11 files changed

+230
-280
lines changed

.github/workflows/cypress.yml

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
name: End-to-end Tests
22

33
on:
4-
- pull_request
4+
workflow_call:
5+
inputs:
6+
pattern:
7+
type: string
8+
required: true
9+
artifact-name:
10+
type: string
11+
required: true
512

613
env:
714
RAILS_ENV: development
815
DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_development
916

1017
jobs:
11-
admin:
12-
name: 'E2E: Admin'
18+
e2e:
19+
name: 'End-to-end'
1320
runs-on: ubuntu-20.04
1421

1522
container:
@@ -95,106 +102,11 @@ jobs:
95102
start: yarn server:start
96103
wait-on: 'http://localhost:3000'
97104
install: false
98-
spec: spec/end-to-end/tests/admin/**.js
105+
spec: ${{ inputs.pattern }}
99106
browser: chrome
100107

101108
- uses: actions/upload-artifact@v3
102109
if: failure()
103110
with:
104-
name: cypress-screenshots-backend
105-
path: spec/end-to-end/screenshots
106-
107-
frontend:
108-
name: 'E2E: Frontend'
109-
runs-on: ubuntu-20.04
110-
111-
container:
112-
image: ruby:3.2.2
113-
114-
services:
115-
postgres:
116-
image: postgres:16
117-
env:
118-
POSTGRES_USER: postgres
119-
POSTGRES_PASSWORD: postgres
120-
POSTGRES_DB: gmmcalcombr_development
121-
ports:
122-
- 5432:5432
123-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
124-
125-
steps:
126-
- uses: actions/checkout@v3
127-
128-
- name: Install APT dependencies
129-
run: |
130-
curl -sL https://deb.nodesource.com/setup_18.x | bash -
131-
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
132-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
133-
apt-get -yqq install nodejs libpq-dev xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
134-
135-
- name: Install Chrome browser
136-
run: |
137-
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
138-
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
139-
apt-get update && \
140-
apt-get install -y dbus-x11 google-chrome-stable && \
141-
rm -rf /var/lib/apt/lists/*
142-
143-
- name: Install yarn
144-
run: npm i -g yarn
145-
146-
- name: Get yarn cache directory path
147-
id: yarn-cache-dir-path
148-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
149-
150-
- uses: actions/cache@v3
151-
with:
152-
path: vendor/bundle
153-
key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }}
154-
restore-keys: |
155-
${{ runner.os }}-gems-gmmcal-
156-
157-
- uses: actions/cache@v3
158-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
159-
with:
160-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
161-
key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
162-
restore-keys: |
163-
${{ runner.os }}-yarn-gmmcal-
164-
165-
# dependencies
166-
- name: Run bundle install
167-
run: |
168-
bundle config path vendor/bundle
169-
bundle install --jobs 4 --retry 3
170-
171-
- name: Run yarn install
172-
run: yarn install
173-
174-
- name: Setup database
175-
run: |
176-
bundle exec rails db:migrate
177-
178-
- name: Compile assets
179-
run: |
180-
bundle exec rails assets:precompile
181-
182-
- name: Load default DB data
183-
run: |
184-
bundle exec rails db:seed
185-
186-
# script
187-
- name: Run tests
188-
uses: cypress-io/github-action@v6
189-
with:
190-
start: yarn server:start
191-
wait-on: 'http://localhost:3000'
192-
install: false
193-
spec: spec/end-to-end/tests/frontend/**.js
194-
browser: chrome
195-
196-
- uses: actions/upload-artifact@v3
197-
if: failure()
198-
with:
199-
name: cypress-screenshots-frontend
111+
name: ${{ inputs.artifact-name }}
200112
path: spec/end-to-end/screenshots

.github/workflows/deploy.yml

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,25 @@ on:
1010
types: [published]
1111

1212
jobs:
13-
docker_production:
14-
name: 'Docker: Production'
15-
runs-on: ubuntu-20.04
16-
17-
if: github.event_name == 'push'
18-
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v4
22-
23-
- name: Set up Docker Buildx
24-
uses: docker/setup-buildx-action@v3
25-
26-
- name: Login to Docker Hub
27-
uses: docker/login-action@v3
28-
with:
29-
username: ${{ secrets.DOCKERHUB_USERNAME }}
30-
password: ${{ secrets.DOCKERHUB_TOKEN }}
31-
32-
- name: Build test image
33-
uses: docker/build-push-action@v5
34-
with:
35-
push: true
36-
context: .
37-
target: production
38-
tags: "gmmcal/gmmcal:latest"
39-
cache-from: type=registry,ref=gmmcal/gmmcal:buildcache
40-
cache-to: type=registry,ref=gmmcal/gmmcal:buildcache,mode=max
41-
42-
docker_development:
43-
name: 'Docker: Development'
44-
runs-on: ubuntu-20.04
45-
13+
build_production:
14+
name: 'Build: Production'
15+
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@reusable
16+
secrets: inherit
17+
with:
18+
target: production
19+
20+
build_development:
21+
name: 'Build: Development'
22+
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@reusable
23+
secrets: inherit
24+
with:
25+
target: development
4626
if: github.event_name == 'push'
4727

48-
steps:
49-
- name: Checkout code
50-
uses: actions/checkout@v4
51-
52-
- name: Set up Docker Buildx
53-
uses: docker/setup-buildx-action@v3
54-
55-
- name: Login to Docker Hub
56-
uses: docker/login-action@v3
57-
with:
58-
username: ${{ secrets.DOCKERHUB_USERNAME }}
59-
password: ${{ secrets.DOCKERHUB_TOKEN }}
60-
61-
- name: Build test image
62-
uses: docker/build-push-action@v5
63-
with:
64-
push: true
65-
context: .
66-
target: development
67-
tags: "gmmcal/gmmcal:development"
68-
cache-from: type=registry,ref=gmmcal/gmmcal:buildcache
69-
cache-to: type=registry,ref=gmmcal/gmmcal:buildcache,mode=max
70-
71-
staging:
28+
deploy_staging:
7229
name: 'Deploy: Staging'
7330
runs-on: ubuntu-20.04
74-
75-
if: github.event_name == 'push'
31+
needs: build_production
7632

7733
steps:
7834
- name: Deploy
@@ -82,9 +38,10 @@ jobs:
8238
run: |
8339
curl -v "https://api.render.com/deploy/srv-$DEPLOY_SERVICE?key=$DEPLOY_KEY&ref=$GITHUB_SHA"
8440
85-
production:
41+
deploy_production:
8642
name: 'Deploy: Production'
8743
runs-on: ubuntu-20.04
44+
needs: deploy_staging
8845

8946
if: github.event_name != 'push'
9047

.github/workflows/docker.yml

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
name: Build
22

33
on:
4-
- push
5-
- pull_request
4+
workflow_call:
5+
inputs:
6+
tag-name:
7+
type: string
8+
required: false
9+
default: "gmmcal/gmmcal"
10+
target:
11+
type: string
12+
required: false
13+
default: test
614

715
jobs:
8-
docker:
9-
name: 'Docker: Build'
16+
build:
17+
name: 'Build Image'
1018
runs-on: ubuntu-20.04
1119

1220
steps:
@@ -22,73 +30,12 @@ jobs:
2230
username: ${{ secrets.DOCKERHUB_USERNAME }}
2331
password: ${{ secrets.DOCKERHUB_TOKEN }}
2432

25-
- name: Build test image
33+
- name: Build image
2634
uses: docker/build-push-action@v5
2735
with:
2836
push: true
2937
context: .
30-
target: test
31-
tags: "gmmcal/gmmcal:test"
38+
target: ${{ inputs.target }}
39+
tags: ${{ inputs.tag-name }}:${{ inputs.target }}
3240
cache-from: type=registry,ref=gmmcal/gmmcal:buildcache
3341
cache-to: type=registry,ref=gmmcal/gmmcal:buildcache,mode=max
34-
35-
rubocop:
36-
name: 'Lint: Rubocop'
37-
runs-on: ubuntu-20.04
38-
needs: docker
39-
40-
steps:
41-
- name: Run rubocop
42-
run: |
43-
docker run --rm gmmcal/gmmcal:test bundle exec rubocop --config .rubocop.yml .
44-
45-
reek:
46-
name: 'Lint: Reek'
47-
runs-on: ubuntu-20.04
48-
needs: docker
49-
50-
steps:
51-
- name: Run reek
52-
run: |
53-
docker run --rm gmmcal/gmmcal:test bundle exec reek --config .reek.yml .
54-
55-
brakeman:
56-
name: 'Lint: Brakeman'
57-
runs-on: ubuntu-20.04
58-
needs: docker
59-
60-
steps:
61-
- name: Run brakeman
62-
run: |
63-
docker run --rm gmmcal/gmmcal:test bundle exec brakeman
64-
65-
scsslint:
66-
name: 'Lint: SCSSLint'
67-
runs-on: ubuntu-20.04
68-
needs: docker
69-
70-
steps:
71-
- name: Run SCSSLint
72-
run: |
73-
docker run --rm gmmcal/gmmcal:test bundle exec scss-lint --config .scss-lint.yml
74-
75-
tests:
76-
name: 'Unit: Backend'
77-
runs-on: ubuntu-20.04
78-
needs: docker
79-
80-
services:
81-
postgres:
82-
image: postgres:16
83-
env:
84-
POSTGRES_USER: postgres
85-
POSTGRES_PASSWORD: postgres
86-
POSTGRES_DB: gmmcalcombr_test
87-
ports:
88-
- 5432:5432
89-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
90-
91-
steps:
92-
- name: Run rubocop
93-
run: |
94-
docker run --network=${{ job.services.postgres.network }} -e DATABASE_URL='postgres://postgres:postgres@postgres:5432/gmmcalcombr_test' -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true --rm gmmcal/gmmcal:test

.github/workflows/lint.yml

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,17 @@
11
name: Lint
22

33
on:
4-
- pull_request
4+
workflow_call:
5+
inputs:
6+
command:
7+
type: string
8+
required: true
59

610
jobs:
7-
bundler-audit:
8-
name: 'Lint: Bundler Audit'
11+
lint:
12+
name: Lint
913
runs-on: ubuntu-20.04
1014

11-
container:
12-
image: ruby:3.2.2
13-
14-
steps:
15-
- uses: actions/checkout@v3
16-
17-
- name: Install Bundler Audit
18-
run: gem install bundler-audit
19-
20-
- name: Update advisory database
21-
run: bundler-audit update
22-
23-
- name: Run bundler-audit
24-
run: bundler-audit
25-
26-
eslint:
27-
name: 'Lint: ESLint'
28-
runs-on: ubuntu-20.04
29-
30-
container:
31-
image: node:18
32-
3315
steps:
34-
- uses: actions/checkout@v4
35-
36-
- name: Get yarn cache directory path
37-
id: yarn-cache-dir-path
38-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
39-
40-
- uses: actions/cache@v3
41-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
42-
with:
43-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
44-
key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
45-
restore-keys: |
46-
${{ runner.os }}-yarn-gmmcal-
47-
48-
- name: Run yarn install
49-
run: yarn install
50-
51-
- name: Run ESLint - Application
52-
run: yarn eslint
53-
54-
- name: Run ESLint - Tests
55-
run: yarn eslint:tests
16+
- name: Execute linter
17+
run: docker run --rm gmmcal/gmmcal:test ${{ inputs.command }}

0 commit comments

Comments
 (0)