-
Notifications
You must be signed in to change notification settings - Fork 9
66 lines (57 loc) · 2.55 KB
/
mirror.yml
File metadata and controls
66 lines (57 loc) · 2.55 KB
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
name: Sync any source updates
on:
workflow_call:
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
- name: install deps
run: gem install octokit faraday-retry faraday-multipart
- name: Pull updates
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
ruby <<-EOF
require "octokit"
client = Octokit::Client.new
today = DateTime.now.strftime('%Y-%m-%d')
repo = %x(git config --get remote.origin.url).strip.split('/').last
origin = "overlookinfra/#{repo}"
upstream = "puppetlabs/#{repo}"
default = client.repo(upstream).default_branch
branches = client.branches(upstream)
.map{|b| b.name }
.select{|n| n =~ /^\d\.x/ }
.unshift(default)
system('git', 'remote', 'add', 'source', "https://github.com/#{upstream}.git")
system('git', 'config', '--global', 'user.email', 'contact@overlookinfratech.com')
system('git', 'config', '--global', 'user.name', 'Overlook InfraTech')
system('git', 'remote', 'set-url', 'origin', "https://#{ENV['WORKFLOW_TOKEN']}@github.com/#{origin}.git")
puts "Origin: #{%x(git config --get remote.origin.url)}"
system('git', 'fetch', 'source', '--tags')
branches.each do |branch|
# There must be a better way, lol
system('git', 'checkout', branch) || system('git', 'checkout', '-b', branch)
# Save a snapshot of today in case branches are deleted in the future
system('git', 'branch', "backup/#{today}/#{branch}")
system('git', 'push', '-u', 'origin', "backup/#{today}/#{branch}", '--force')
# Now integrate any updates, while deleting any workflow files so we don't accidentally run them.
system('git', 'pull', 'source', branch, '--rebase')
system('git', 'rm', '.github/workflows/*')
system('git', 'commit', '-m', 'Removing workflow files')
# force pushing allows the local commits to "float" at the top of the history
system('git', 'push', '-u', 'origin', branch, '--force')
end
system('git', 'push', 'origin', '--tags')
EOF