Skip to content

Commit eb49ce5

Browse files
committed
Script supports maven build type
1 parent bc56342 commit eb49ce5

2 files changed

Lines changed: 189 additions & 1 deletion

File tree

src/actionhelper.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
1-
print("Goodbye, World!")
1+
import os
2+
import sys
3+
import getopt
4+
import fileinput
5+
6+
def main(argv):
7+
#Set up defaults for when no options are passed
8+
buildType = 'mvn'
9+
inFile = 'templates/maven_template.yml'
10+
outFile = './maven.yml'
11+
token_artifact_name = 'ARTIFACT_NAME'
12+
data_to_insert = 'MyProject'
13+
try:
14+
opts, args = getopt.getopt(argv, "ht:o:n:", ["type=", "output=", "name="])
15+
except getopt.GetoptError:
16+
print("actionhelper -t <build type> -o <output file>")
17+
sys.exit(2)
18+
for opt, arg in opts:
19+
if opt == '-h':
20+
print("actionhelper -t <build type> -o <output file> -n <artifact name>")
21+
print("Default options:")
22+
print("Type = mvn")
23+
print("Output file = maven.yml")
24+
print("Name = MyProject")
25+
sys.exit()
26+
elif opt in ("-t", "--type"):
27+
buildType = arg
28+
elif opt in ("-o", "--output"):
29+
outFile = arg
30+
elif opt in ("-n", "--name"):
31+
data_to_insert = arg
32+
print("Creating workflow file", outFile, "with build type", buildType)
33+
34+
if buildType == "mvn" or buildType == "maven":
35+
inFile = "templates/maven_template.yml"
36+
37+
app_path = "./"
38+
if getattr(sys, 'frozen', False):
39+
app_path = os.path.dirname(sys.executable)
40+
else:
41+
app_path = os.path.dirname(os.path.abspath(__file__))
42+
43+
inputFile = os.path.join(app_path, inFile)
44+
f = open(inputFile, 'r')
45+
filedata = f.read()
46+
f.close()
47+
48+
newdata = filedata.replace(token_artifact_name, data_to_insert)
49+
50+
f = open(outFile, 'w')
51+
f.write(newdata)
52+
f.close()
53+
54+
55+
if __name__ == "__main__":
56+
main(sys.argv[1:])

src/templates/maven_template.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
# This is a basic workflow to help you get started with Actions
3+
4+
name: Create Releases
5+
6+
# Controls when the action will run. Triggers the workflow on push or pull request
7+
# events but only for the master branch
8+
on:
9+
push:
10+
branches: [ master ]
11+
pull_request:
12+
branches: [ master ]
13+
14+
jobs:
15+
create-main-release:
16+
if: "startsWith(github.event.commits[0].message, 'v') && !contains(github.event.commits[0].message, '-SNAPSHOT')"
17+
name: Create Release
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
- name: Set up JDK 1.8
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: 1.8
26+
- name: Cache Maven Packages
27+
uses: actions/cache@v1
28+
with:
29+
path: ~/.m2
30+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
31+
restore-keys: ${{ runner.os }}-m2
32+
- name: Build with Maven
33+
run: mvn clean install
34+
- name: Archive jar
35+
run: mkdir staging && cp target/*.jar staging
36+
- name: upload jar
37+
uses: actions/upload-artifact@v1
38+
with:
39+
name: ARTIFACT_NAME ${{ github.event.commits[0].message }}
40+
path: staging
41+
- name: Create Release
42+
id: create_release
43+
uses: actions/create-release@v1
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
with:
47+
tag_name: ${{ github.event.commits[0].message }}
48+
release_name: JDAExtended ${{ github.event.commits[0].message }}
49+
body: ${{ github.event.commits[0].message }}
50+
draft: false
51+
prerelease: false
52+
- name: Upload Release Asset
53+
id: upload-release-asset
54+
uses: actions/upload-release-asset@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
59+
asset_path: staging/ARTIFACT_NAME.jar
60+
asset_name: ARTIFACT_NAME.jar
61+
asset_content_type: application/java-archive
62+
create-pre-release:
63+
if: "startsWith(github.event.commits[0].message, 'v') && contains(github.event.commits[0].message, '-SNAPSHOT')"
64+
name: Create Pre Release
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v2
69+
- name: Set up JDK 1.8
70+
uses: actions/setup-java@v1
71+
with:
72+
java-version: 1.8
73+
- name: Cache Maven Packages
74+
uses: actions/cache@v1
75+
with:
76+
path: ~/.m2
77+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
78+
restore-keys: ${{ runner.os }}-m2
79+
- name: Build with Maven
80+
run: mvn clean install
81+
- name: Archive jar
82+
run: mkdir staging && cp target/*.jar staging
83+
- name: upload jar
84+
uses: actions/upload-artifact@v1
85+
with:
86+
name: ARTIFACT_NAME ${{ github.event.commits[0].message }}
87+
path: staging
88+
- name: Create Release
89+
id: create_release
90+
uses: actions/create-release@v1
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
with:
94+
tag_name: ${{ github.event.commits[0].message }}
95+
release_name: ARTIFACT_NAME ${{ github.event.commits[0].message }}
96+
body: ${{ github.event.commits[0].message }}
97+
draft: false
98+
prerelease: true
99+
- name: Upload Release Asset
100+
id: upload-release-asset
101+
uses: actions/upload-release-asset@v1
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
with:
105+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
106+
asset_path: staging/ARTIFACT_NAME.jar
107+
asset_name: ARTIFACT_NAME.jar
108+
asset_content_type: application/java-archive
109+
main:
110+
if: "!startsWith(github.event.commits[0].message, 'v')"
111+
name: Create Dev Build
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/checkout@v2
115+
- name: Set up JDK 1.8
116+
uses: actions/setup-java@v1
117+
with:
118+
java-version: 1.8
119+
- name: Cache Maven Packages
120+
uses: actions/cache@v1
121+
with:
122+
path: ~/.m2
123+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
124+
restore-keys: ${{ runner.os }}-m2
125+
- name: Build with Maven
126+
run: mvn clean install
127+
- name: Archive jar
128+
run: mkdir staging && cp target/*.jar staging
129+
- name: upload jar
130+
uses: actions/upload-artifact@v1
131+
with:
132+
name: ARTIFACT_NAME-DEVELOPMENT-BUILD
133+
path: staging

0 commit comments

Comments
 (0)