Skip to content

Commit dbaf9f4

Browse files
authored
Merge pull request #69 from Heshdude/improving-automation
Adding automatic PR creation for generated README.md & installers.toml
2 parents 4a72995 + b735a82 commit dbaf9f4

File tree

5 files changed

+70
-23
lines changed

5 files changed

+70
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,64 @@ jobs:
1111
steps:
1212
- name: Checkout Repo
1313
uses: actions/checkout@master
14-
- name: Get the list of modified files only
14+
- name: Get the list of modified installers only
1515
uses: technote-space/get-diff-action@v1
16-
- name: Generate installers
17-
run: pip install toml && python generate.py ${{ env.GIT_DIFF }}
16+
with:
17+
PREFIX_FILTER: |
18+
installers/
19+
- name: Generate installers, update README.md & installers.toml
20+
if: env.GIT_DIFF
21+
run: ./generate.sh ${{ env.GIT_DIFF }}
1822
- name: Minify generated installers
23+
if: env.GIT_DIFF
1924
run: ./minify.sh ${{ env.GIT_DIFF }}
25+
- name: Find the Related PR
26+
if: env.GIT_DIFF
27+
uses: jwalton/gh-find-current-pr@v1
28+
id: findPr
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
- name: Related PR
32+
if: env.GIT_DIFF && success() && steps.findPr.outputs.number
33+
id: vars
34+
run: |
35+
echo "The related PR is ${PR}"
36+
echo ::set-output name=pr_id::"${PR}"
37+
env:
38+
PR: ${{ steps.findPr.outputs.pr }}
39+
- name: Create a pull request for README.md & installers.toml updates
40+
if: env.GIT_DIFF
41+
uses: peter-evans/create-pull-request@v3
42+
with:
43+
commit-message: Update installer scripts, README.md & installers.toml
44+
title: |
45+
Update installer scripts, README.md & installers.toml for #${{ steps.vars.outputs.pr_id }}
46+
body: |
47+
Updated installer scripts, `README.md` & `installers.toml` according to the changes done in the `installer.toml`s.
48+
This is a automatically generated PR in related to PR #${{ steps.vars.outputs.pr_id }}
49+
branch: update-readme-md-and-installers-toml-${{ steps.vars.outputs.pr_id }}
50+
labels: automated-pr, continious-delivery
2051
- name: Archive Production Artifact
52+
if: env.GIT_DIFF
2153
uses: actions/upload-artifact@master
2254
with:
2355
name: installers
2456
path: installers
57+
2558
deploy:
2659
name: Deploy
2760
needs: build
2861
runs-on: ubuntu-latest
2962
steps:
3063
- name: Checkout Repo
3164
uses: actions/checkout@master
65+
- name: Get the list of modified installers only
66+
uses: technote-space/get-diff-action@v1
67+
with:
68+
PREFIX_FILTER: |
69+
installers/
3270
- name: Download Artifact
71+
if: env.GIT_DIFF
3372
uses: actions/download-artifact@master
3473
with:
3574
name: installers

.github/workflows/dockerimage.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
21
name: Run tests
32

43
on:
5-
64
push:
75
branches: [ master ]
86

97
pull_request:
108
branches: [ master ]
119

12-
1310
jobs:
1411

1512
test-on-ubuntu:
16-
1713
runs-on: ubuntu-latest
1814
steps:
19-
- uses: actions/checkout@v2
20-
- uses: technote-space/get-diff-action@v1
21-
- name: Get the list of modified files only
22-
run: pip install toml pytablewriter && python generate.py ${{ env.GIT_DIFF }} && docker build -t shellspec . && docker run -v $PWD:/app shellspec bash -c "cd /app && ./test.sh ${{ env.GIT_DIFF }}"
15+
- uses: actions/checkout@v2
16+
- uses: technote-space/get-diff-action@v1
17+
- name: Run tests for the modified/ added files
18+
run: |
19+
pip install toml pytablewriter
20+
python generate.py ${{ env.GIT_DIFF }}
21+
docker build -t shellspec .
22+
docker run -v $PWD:/app shellspec bash -c "cd /app && ./test.sh ${{ env.GIT_DIFF }}"

generate.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def update_readme(summary):
3131
curl = "Yes" if "curl" in installers else "No"
3232
url = "https://installer.to/"+tool_shortname
3333
value_matrix.append([name, apt, yum, pacman, apk, dnf, curl, url])
34-
print(value_matrix)
34+
3535
writer.value_matrix = value_matrix
3636
table_md = writer.dumps()
3737
try:
@@ -46,32 +46,28 @@ def update_readme(summary):
4646
readme_md.write(readme)
4747
readme_md.close()
4848
except Error as e:
49-
print(e)
49+
logging.error('Error occurred when trying to update README.md, error: '+ e)
5050

5151

5252
def update_summary(name, shortname, description, installers):
5353
try:
5454
with open("./installers.toml", "r+") as installer_summary:
5555
summaary = installer_summary.read()
56-
print (summaary)
5756
parsed_summary_toml = toml.loads(summaary)
58-
print (parsed_summary_toml)
5957
if shortname not in parsed_summary_toml:
6058
parsed_summary_toml[shortname] = {}
6159
parsed_summary_toml[shortname]['name'] = name
6260
parsed_summary_toml[shortname]['name'] = name
6361
parsed_summary_toml[shortname]['description'] = description
6462
parsed_summary_toml[shortname]['installers'] = ",".join(installers)
65-
print (parsed_summary_toml)
6663
installer_summary.seek(0) # sets point at the beginning of the file
6764
installer_summary.truncate() # Clear previous content
6865
installer_summary.write(toml.dumps(parsed_summary_toml))
6966
installer_summary.close()
7067

7168
update_readme(parsed_summary_toml)
7269
except IOError as e:
73-
print ("Error", e)
74-
pass
70+
logging.error('Error occurred when trying to update installers.toml, error: '+ e)
7571

7672
def get_method_case(method):
7773
if method in methods:
@@ -167,7 +163,6 @@ def generate(path):
167163

168164
installer_sh.close()
169165
update_summary(parsed_toml['name'], parsed_toml['shortname'], parsed_toml['description'], installer_methods)
170-
print("installer_methods",installer_methods)
171166

172167
except IOError as x:
173168
if x.errno == errno.EACCES:

generate.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
X=()
4+
5+
for word in "$@"; do
6+
X+=$(dirname "$word " | cut -d "/" -f "1 2")" "
7+
done
8+
9+
CHANGED=$(echo $X | tr ' ' '\n' | sort | uniq | xargs)
10+
11+
echo "generating for $CHANGED"
12+
pip install toml
13+
pip install pytablewriter
14+
python generate.py $CHANGED

installers/hlf/installer.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ description = "Hyperledger Fabric"
77
sh = """
88
if ! command -v docker
99
then
10-
@warn "docker could not be found"
10+
@warn "Docker could not be found"
1111
curl https://installer.to/docker | bash
1212
else
13-
@info "docker found"
13+
@info "Docker found"
1414
fi
1515
16-
@info "downloading Fabric........"
16+
@info "Downloading Fabric........"
1717
curl -sSL http://bit.ly/2ysbOFE -o bootstrap.sh
1818
chmod 755 ./bootstrap.sh
1919
@sudo bash ./bootstrap.sh
2020
2121
@sudo cp ./fabric-samples/bin/* /usr/local/bin
22-
2322
"""

0 commit comments

Comments
 (0)