-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (152 loc) · 5.56 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.
#
# This workflow will install a prebuilt Ruby version, install dependencies, and
# run tests and linters.
# NOTE: https://github.saobby.my.eu.orgmunity/t/retry-for-failed-steps/17136/7
name: 'Ruby on Rails CI'
on:
pull_request:
branches:
- develop
- main
# concurrency:
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: true
jobs:
test-next:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: Extract Ruby Version
id: ruby_version
run: |
major_minor_version=$(grep -A 1 "RUBY VERSION" Gemfile.next.lock | tail -n 1 | awk '{split($2,a,"[p.]"); print a[1] "." a[2]}')
echo "MAJOR_MINOR_VERSION=$major_minor_version" >> $GITHUB_ENV
- name: Setup Ruby 3
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.MAJOR_MINOR_VERSION }}
bundler-cache: true
env:
BUNDLE_GEMFILE: Gemfile.next
- name: Build next and unit test
env:
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_KEY }}
CI: true
continue-on-error: false
run: |
# should update dependabot to manage the Gemfile.next.lock
bin/setup-next
next rails test:prepare --trace
next rails test
- name: system-test-next
id: system-test-next
continue-on-error: false
env:
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_KEY }}
CI: true
run: |
next bin/rails test:system HEADLESS=true CUPRITE=true CUPRITE_JS_ERRORS=true APP_HOST='127.0.0.1'
test:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: Extract Ruby Version
id: ruby_version
run: |
major_minor_version=$(grep -A 1 "RUBY VERSION" Gemfile.lock | tail -n 1 | awk '{split($2,a,"[p.]"); print a[1] "." a[2]}')
echo "MAJOR_MINOR_VERSION=$major_minor_version" >> $GITHUB_ENV
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.MAJOR_MINOR_VERSION }}
bundler-cache: true
- name: brakeman
run: |
gem install brakeman
brakeman --no-pager --quiet
- name: Build and run unit-tests
env:
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_KEY }}
CI: true
run: |
bin/setup
# test prepare required for tailwind css file required in application erb
bin/rails test:prepare --trace
bin/rails test
- name: system-tests
id: system-test
continue-on-error: true # make the step always success and set status later
env:
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_KEY }}
CI: true
run: |
bin/rails test:system HEADLESS=true CUPRITE=true CUPRITE_JS_ERRORS=true APP_HOST='127.0.0.1'
- name: system-test-retry
id: system-test-retry-1
continue-on-error: true # make the step always success and set status later
if: steps.system-test.outcome=='failure' # check the step outcome, retry 1st time
env:
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_KEY }}
run: |
bin/rails test:system --verbose HEADLESS=true CUPRITE=true CUPRITE_JS_ERRORS=true APP_HOST='127.0.0.1'
- name: Upload failed system test images
uses: actions/upload-artifact@v4
if: steps.system-test.outcome=='failure' || steps.system-test-retry-1.outcome=='failure' # check the step outcome, retry 1st time
with:
path: ./tmp/capybara/screenshots/failures_*.png
- name: set the status # set the workflow status if command failed
if: steps.system-test.outcome=='failure'
run: |
if ${{ steps.system-test-retry-1.outcome=='success' }}; then
echo 'the first system test failed, but the second one passed'
else
echo 'the first system test failed, and the second one also failed'
exit 1
fi
auto-merge:
name: Auto-Merge PRs by Dependabot
needs: test
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: fastify/github-action-merge-dependabot@v3.10.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
target: minor
deploy:
needs: test
if: ${{ github.ref == 'refs/heads/develop' }}
runs-on: ubuntu-latest
environment: staging
steps:
- name: checkout code
uses: actions/checkout@v4
- name: Extract Ruby Version
id: ruby_version
run: |
major_minor_version=$(grep -A 1 "RUBY VERSION" Gemfile.lock | tail -n 1 | awk '{split($2,a,"[p.]"); print a[1] "." a[2]}')
echo "MAJOR_MINOR_VERSION=$major_minor_version" >> $GITHUB_ENV
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.MAJOR_MINOR_VERSION }}
bundler-cache: true
- name: deploy to heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
gem install dpl && gem install faraday -v '~> 1.8.0'
dpl --provider=heroku --api-key=${HEROKU_API_KEY} --app=${HEROKU_APP_NAME}