Skip to content

Commit f6475b3

Browse files
authored
chore/git-init-workflow-convenience (#218)
1 parent af4196e commit f6475b3

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

config/recipes/repo/push.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
if ! git ls-remote origin refs/for/release | grep -q "$(git rev-parse HEAD)"; then
1313
if { [ "#{repository}" != "./" ] && [ "#{is_bootstrap}" = "false" ]; } || \
1414
{ [ "#{repository}" = "./" ] && [ "#{is_bootstrap}" = "true" ]; }; then
15-
git push origin HEAD:refs/for/release \
16-
-o topic="release" \
17-
-o title="Release Pull Request" \
18-
-o description="Created automatically for deployment." \
19-
-o force-push
15+
git push origin HEAD:refs/for/release -o topic="release" -o title="Release Pull Request" \
16+
-o description="Created automatically for deployment." -o force-push
2017
fi
18+
git push -u origin HEAD:snapshot
2119
fi
2220
fi
2321
EOH
2422
end
2523

26-
execute "repo_#{name_repo}_push_snapshot" do
24+
execute "repo_#{name_repo}_push_rollback" do
2725
command <<-EOH
2826
cp -r #{path_destination}/.git #{path_working}
2927
cd #{path_working} && git checkout -b #{node['git']['branch']['rollback']} && git add -A
@@ -32,6 +30,6 @@
3230
EOH
3331
cwd path_destination
3432
user node['app']['user']
35-
only_if { Logs.info("[#{repository} (#{name_repo})]: snapshot commit")
33+
only_if { Logs.info("[#{repository} (#{name_repo})]: rollback commit")
3634
node.run_state["#{name_repo}_repo_exists"] }
3735
end

config/recipes/task.rb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
block do
5151
uri = "#{node['git']['api']['endpoint']}/admin/users/#{node['git']['org']['tasks']}/repos"
5252
r = Utils.request(uri, method: Net::HTTP::Post, headers: Constants::HEADER_JSON,
53-
user: Env.get(self, 'login'), pass: Env.get(self, 'password'),
54-
body: { name: name_repo, private: false, auto_init: false, default_branch: 'main' }.json)
53+
user: Env.get(self, 'login'), pass: Env.get(self, 'password'),
54+
body: { name: name_repo, private: false, auto_init: false, default_branch: 'main' }.json)
5555
Logs.request!(uri, r, [201], msg: "Create #{name_repo}")
5656
r.json
5757
end
@@ -69,10 +69,7 @@
6969
owner node['app']['user']
7070
group node['app']['group']
7171
mode '0644'
72-
variables(repo: name_repo,
73-
config: node['app']['config'],
74-
org: node['git']['org']['tasks'],
75-
ssh: node['git']['host']['ssh'])
72+
variables(repo: name_repo, config: node['app']['config'], org: node['git']['org']['tasks'], ssh: node['git']['host']['ssh'])
7673
only_if { ::File.directory?("#{path_destination}/.git") }
7774
end
7875

@@ -101,10 +98,9 @@
10198
m = File.join(path_destination, 'main.rb')
10299
g = Dir.glob(File.join(path_destination, '*.rb')).sort
103100
s = if File.file?(d); 'default.rb'
104-
elsif File.file?(m); 'main.rb'
105-
elsif g.any?; File.basename(g.first)
106-
end
107-
raise 'no ruby script found' unless s
101+
elsif File.file?(m); 'main.rb'
102+
elsif g.any?; File.basename(g.first)
103+
end
108104
node.run_state["#{name_repo}_script"] = s
109105
end
110106
end
@@ -124,11 +120,8 @@
124120
owner node['app']['user']
125121
group node['app']['group']
126122
mode '0644'
127-
variables lazy { {
128-
org: node['git']['org']['tasks'],
129-
repo: name_repo,
130-
script: node.run_state["#{name_repo}_script"],
131-
cron: node.run_state["#{name_repo}_cron"] } }
123+
variables lazy { { org: node['git']['org']['tasks'], repo: name_repo,
124+
script: node.run_state["#{name_repo}_script"], cron: node.run_state["#{name_repo}_cron"] } }
132125
end
133126

134127
execute "task_repo_base_commit_#{name_repo}" do
@@ -141,6 +134,20 @@
141134
user node['app']['user']
142135
end
143136

137+
execute "task_repo_touch_workflow_#{name_repo}" do
138+
command <<-EOH
139+
WORKFLOW_FILE="#{path_destination}/.gitea/workflows/ruby.yml"
140+
if [ -f "$WORKFLOW_FILE" ]; then
141+
touch "$WORKFLOW_FILE" && git add "$WORKFLOW_FILE"
142+
git commit --allow-empty -m "touch workflow [skip ci]" || true
143+
git push origin main || true
144+
fi
145+
EOH
146+
cwd path_destination
147+
user node['app']['user']
148+
not_if { ['127.0.0.1', 'localhost', '::1'].include?(Env.get(self, 'host')) }
149+
end
150+
144151
directory path_destination do
145152
action :delete
146153
recursive true

0 commit comments

Comments
 (0)