Skip to content

Commit 3d28e12

Browse files
committed
Loading Rails config
1 parent 107ef83 commit 3d28e12

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Rails Upgrade runner
2+
on: push
3+
jobs:
4+
upgrade-rails:
5+
runs-on: "ubuntu-latest"
6+
timeout-minutes: 30
7+
permissions:
8+
contents: write
9+
defaults:
10+
run:
11+
working-directory: "."
12+
13+
services:
14+
mysql:
15+
image: mysql:8.0
16+
ports: ["3306:3306"]
17+
env:
18+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
19+
redis:
20+
image: redis
21+
ports: ["6379:6379"]
22+
memcached:
23+
image: memcached
24+
ports: ["11211:11211"]
25+
26+
env:
27+
RAILS_UPGRADE: 1
28+
DATABASE_URL: mysql2://[email protected]:3306/rails_upgrade
29+
MYSQL_HOST: 127.0.0.1
30+
MYSQL_PORT: 3306
31+
MYSQL_USER: root
32+
REDIS_URL: redis://localhost:6379/0
33+
REDIS_HOST: localhost
34+
REDIS_PORT: 6379
35+
TOXIPROXY_URL: http://127.0.0.1:8474
36+
TOXIPROXY_HOST: 127.0.0.1
37+
TOXIPROXY_PORT: 8474
38+
DISABLE_TOXIPROXY: 1
39+
MEMCACHE_SERVERS: localhost:11211
40+
41+
steps:
42+
- name: Check out code
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 2
46+
- name: Check out rails_upgrade
47+
uses: actions/checkout@v4
48+
with:
49+
repository: Shopify/rails_upgrade
50+
path: "./tmp/rails_upgrade"
51+
token: ${{ secrets.RAILS_UPGRADE_GITHUB }}
52+
- name: Check out rails_upgrade-shopify
53+
uses: actions/checkout@v4
54+
with:
55+
repository: Shopify/rails_upgrade-shopify
56+
path: "./tmp/rails_upgrade-shopify"
57+
token: ${{ secrets.RAILS_UPGRADE_GITHUB }}
58+
- name: Get Ruby version
59+
id: ruby
60+
shell: ruby -ryaml {0}
61+
run: |
62+
return unless File.exist?("dev.yml")
63+
yaml = YAML.respond_to?(:unsafe_load_file) ? YAML.unsafe_load_file("dev.yml") : YAML.load_file("dev.yml")
64+
ruby_version = yaml["up"]
65+
&.detect {|h| Hash === h && h.key?("ruby") }&.dig("ruby")
66+
.then {|c| Hash === c ? c["version"] : c }
67+
return unless ruby_version
68+
File.write(ENV.fetch("GITHUB_OUTPUT"), "version=#{ruby_version}\n", mode: "a")
69+
- name: Setup dependencies declared in Shopify Build pipelines
70+
shell: ruby -ryaml -rset {0}
71+
run: |
72+
packages, keys, repos = Set.new, Set.new, Set.new
73+
Dir[".shopify-build/**/*.yml"].each do |file|
74+
pipeline = YAML.respond_to?(:unsafe_load_file) ? YAML.unsafe_load_file(file) : YAML.load_file(file)
75+
containers = pipeline["containers"]
76+
next unless containers
77+
containers.each_value do |container|
78+
next unless apt = container.dig("build", "apt")
79+
packages.merge(apt["install"] || [])
80+
keys.merge(apt["keys"] || [])
81+
repos.merge(apt["repos"] || [])
82+
end
83+
rescue
84+
puts "Error in pipeline #{file}: #{$!}"
85+
end
86+
return if packages.empty?
87+
keys.each { |key| system(%(curl -s "#{key}" | sudo apt-key add -), exception: true) }
88+
repos.each { |repo| system("sudo", "sh", "-c", %(echo "#{repo}" >> /etc/apt/sources.list.d/custom.list), exception: true) }
89+
system("sudo", "apt-get", "update", exception: true)
90+
exec("sudo", "apt-get", "install", "--yes", "--option", "DPkg::Lock::Timeout=60", *packages)
91+
- name: Setup Git configuration
92+
run: |
93+
git config --global http.https://github.com.extraheader "Authorization: Basic $(echo -n "x-access-token:${{ secrets.RAILS_UPGRADE_GITHUB }}" | base64)"
94+
echo "$(git rev-parse --show-prefix)"vendor/bundle >> "$(git rev-parse --git-dir)/info/exclude"
95+
git config --local user.email "[email protected]"
96+
git config --local user.name "Ruby & Rails infrastructure"
97+
git checkout HEAD^ # Remove commit that includes the workflow
98+
- name: Setup Git submodules
99+
run: |
100+
git submodule update --init --recursive --depth=1
101+
- name: Set up Ruby
102+
uses: ruby/setup-ruby@v1
103+
with:
104+
ruby-version: ${{ steps.ruby.outputs.version }}
105+
bundler-cache: true
106+
working-directory: "."
107+
env:
108+
BUNDLE_PKGS__SHOPIFY__IO: ${{ secrets.RAILS_UPGRADE_PKGS_SHOPIFY_IO }}
109+
- name: Install rails_upgrade
110+
run: |
111+
cd tmp/rails_upgrade
112+
rake install
113+
- name: Install rails_upgrade-shopify
114+
run: |
115+
cd tmp/rails_upgrade-shopify
116+
rake install
117+
- name: Set up DATABASE_URL scheme
118+
run: |
119+
if bundle list | grep --fixed-strings --quiet ' trilogy '; then
120+
echo "DATABASE_URL=${DATABASE_URL/mysql2/trilogy}" >> "$GITHUB_ENV"
121+
fi
122+
123+
- name: Setup the application before upgrading
124+
run: |
125+
bin/setup --skip-server
126+
if test -n "$(git status --porcelain)"; then
127+
if test "$(\
128+
git diff -U0 --word-diff=porcelain --word-diff-regex='[0-9.]+|[^[:space:]]' |\
129+
grep --invert-match --extended-regexp --count\
130+
-e '^(diff|index|---|\+\+\+|@@) ' -e '^~$' -e '^ ActiveRecord::Schema\[$' -e '^ \].define')"\
131+
-eq 2 ; then
132+
echo "Removing Active Record schema class version change:"
133+
git diff
134+
git checkout -- db/schema.rb
135+
exit 0
136+
fi
137+
echo "There are uncommitted changes after running bin/setup:"
138+
git status --porcelain
139+
git config --global --unset http.https://github.com.extraheader
140+
git add .
141+
git commit -m "uncommitted changes" || true
142+
git push --force origin HEAD:refs/heads/rails-upgrade/uncommitted
143+
echo "Pushed these uncommitted changes to the rails-upgrade/uncommitted branch:"
144+
echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)"
145+
exit 1
146+
else
147+
git config --global --unset http.https://github.com.extraheader
148+
git push --delete origin rails-upgrade/uncommitted || true
149+
fi
150+
env:
151+
DISABLE_SPRING: "1"
152+
- name: Dump configuration
153+
shell: bash
154+
run: |
155+
rails_upgrade config 3>tmp/rails_upgrade-config.json
156+
- name: Upload configuration
157+
uses: actions/upload-artifact@v4
158+
with:
159+
name: rails_upgrade-config
160+
path: ./tmp/rails_upgrade-config.json

0 commit comments

Comments
 (0)