-
Notifications
You must be signed in to change notification settings - Fork 2
107 lines (93 loc) · 3.66 KB
/
setup.yml
File metadata and controls
107 lines (93 loc) · 3.66 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
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
name: Setup
on: push
jobs:
setup:
if: (github.event.commits[0].message == 'Initial commit') && (github.run_number == 1)
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Set up GO
uses: actions/setup-go@v2
with:
go-version: "1.16"
- name: Copy Repository Contents
uses: actions/checkout@v2
- name: remove old files
run: |
rm go.mod go.sum
- name: modify files
run: |
import re, os
from pathlib import Path
from configparser import ConfigParser
nwo = os.getenv('GITHUB_REPOSITORY')
username, repo_name = nwo.split('/')
readme_path = Path('README.md')
serv_path = Path('pkg/serv/serv.go')
msg_path = Path('pkg/pbs/messages.proto')
svc_path = Path('pkg/pbs/services.proto')
server_path = Path('cmd/server/main.go')
client_path = Path('cmd/client/main.go')
readme = readme_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
serv = serv_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
msg = msg_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
svc = svc_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
server = server_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
client = client_path.read_text().replace('codingpot/server-client-template-go', username + '/' + repo_name)
readme_path.write_text(readme)
serv_path.write_text(serv)
msg_path.write_text(msg)
svc_path.write_text(svc)
server_path.write_text(server)
client_path.write_text(client)
shell: python
- name: get unsername and reponame
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
run: |
export username="$(cut -d'/' -f1 <<<$GITHUB_REPOSITORY)"
export repo_name="$(cut -d'/' -f2 <<<$GITHUB_REPOSITORY)"
echo "::set-env name=username::$username"
echo "::set-env name=repo_name::$repo_name"
- name: go mod && tidy
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
run: |
echo github.com/$username/$repo_name
go mod init github.com/$username/$repo_name
go mod tidy
- name: protoc
run: |
make clean
make install all
- name: commit changes
run: |
git config --global user.email "${GH_EMAIL}"
git config --global user.name "${GH_USERNAME}"
git checkout -B automated-setup
git rm .github/workflows/setup.yml
git add go.mod go.sum
git add .
git commit -m'setup repo'
git push -f --set-upstream origin automated-setup
env:
GH_EMAIL: ${{ github.event.commits[0].author.email }}
GH_USERNAME: ${{ github.event.commits[0].author.username }}
- name: Open a PR
uses: actions/github-script@0.5.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var contents = 'your initial PR';
github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Initial Setup',
head: 'automated-setup',
base: 'main',
body: `${contents}`
});