Skip to content

Commit f85a254

Browse files
committed
Add GitHub actions
1 parent a5edafd commit f85a254

File tree

9 files changed

+321
-2
lines changed

9 files changed

+321
-2
lines changed

.github/actions/build/action.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 'Build'
2+
description: 'Run a Gradle build'
3+
inputs:
4+
tasks:
5+
description: "Gradle tasks"
6+
required: true
7+
artifact-name:
8+
description: "Artifact name"
9+
required: false
10+
path-to-upload:
11+
description: "Path to upload as artifact"
12+
required: false
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Set up Java
17+
uses: actions/setup-java@v2
18+
with:
19+
distribution: temurin
20+
java-version: 8
21+
- name: Set up Gradle env
22+
uses: gradle/gradle-build-action@v2.1.4
23+
- name: Run Gradle tasks
24+
shell: bash
25+
run: |
26+
echo "::group::Gradle build log"
27+
./gradlew ${{ inputs.tasks }}
28+
echo "::endgroup::"
29+
- name: Upload
30+
if: ${{ inputs.path-to-upload }}
31+
uses: actions/upload-artifact@v3.0.0
32+
with:
33+
name: ${{ inputs.artifact-name }}
34+
path: ${{ inputs.path-to-upload }}
35+
if-no-files-found: error
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
3+
4+
def get_current_api_spec_version(properties_file) -> str:
5+
with open(properties_file, mode='r') as file:
6+
for line in file.readlines():
7+
if '=' not in line:
8+
continue
9+
k, v = line.strip().split('=', maxsplit=2)
10+
if k == 'gradle.enterprise.version':
11+
return v
12+
13+
14+
def main(properties_file):
15+
print(get_current_api_spec_version(properties_file))
16+
17+
18+
if __name__ == '__main__':
19+
main(properties_file='gradle.properties')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
from read_current_api_spec_version import main
4+
from tempfile import NamedTemporaryFile
5+
import unittest
6+
from unittest import mock
7+
8+
9+
class TestReadCurrentApiSpecVersion(unittest.TestCase):
10+
11+
def setUp(self):
12+
self.properties_file = NamedTemporaryFile()
13+
self.properties_file.write(b'gradle.enterprise.version=2022.4\n1=2\n')
14+
self.properties_file.flush()
15+
16+
def tearDown(self):
17+
self.properties_file.close()
18+
19+
@mock.patch('builtins.print')
20+
def test_main(self, mock_print):
21+
main(self.properties_file.name)
22+
mock_print.assert_called_once_with('2022.4')
23+
24+
25+
if __name__ == '__main__':
26+
unittest.main()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
from update_api_spec_version import main
4+
from tempfile import NamedTemporaryFile
5+
import unittest
6+
from unittest import mock
7+
8+
9+
class TestCheckForNewApiSpec(unittest.TestCase):
10+
11+
def setUp(self):
12+
self.properties_file = NamedTemporaryFile()
13+
self.properties_file.write(b'gradle.enterprise.version=2022.4\n1=2\n')
14+
self.properties_file.flush()
15+
16+
def tearDown(self):
17+
self.properties_file.close()
18+
19+
@mock.patch('builtins.print')
20+
@mock.patch('requests.get')
21+
def test_main_many_updates_available(self, mock_get, mock_print):
22+
mock_get.return_value.status_code = 200
23+
24+
main(self.properties_file.name)
25+
26+
with open(self.properties_file.name) as file:
27+
self.assertEqual(file.read(),
28+
'gradle.enterprise.version=2023.4\n1=2\n')
29+
mock_get.assert_called_once_with(
30+
'https://docs.gradle.com/enterprise/api-manual/ref/gradle-enterprise-2023.4-api.yaml'
31+
)
32+
33+
@mock.patch('builtins.print')
34+
@mock.patch('requests.get')
35+
def test_main_no_updates_available(self, mock_get, mock_print):
36+
mock_get.return_value.status_code = 404
37+
38+
main(self.properties_file.name)
39+
40+
with open(self.properties_file.name) as file:
41+
self.assertEqual(file.read(),
42+
'gradle.enterprise.version=2022.4\n1=2\n')
43+
mock_get.assert_has_calls([
44+
mock.call(
45+
'https://docs.gradle.com/enterprise/api-manual/ref/gradle-enterprise-2023.4-api.yaml'),
46+
mock.call(
47+
'https://docs.gradle.com/enterprise/api-manual/ref/gradle-enterprise-2022.5-api.yaml'),
48+
])
49+
50+
51+
if __name__ == '__main__':
52+
unittest.main()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
3+
import requests
4+
import fileinput
5+
import sys
6+
from read_current_api_spec_version import get_current_api_spec_version
7+
8+
9+
def get_possible_version_bumps(version: str) -> list[str]:
10+
parts: list = version.split('.')
11+
possible_bumps = []
12+
for i in range(len(parts)):
13+
bump = parts.copy()
14+
bumped_part = int(bump[i]) + 1
15+
bump[i] = str(bumped_part)
16+
possible_bumps.append(".".join(bump))
17+
return possible_bumps
18+
19+
20+
def get_first_available_version(versions: list[str]) -> str:
21+
for version in versions:
22+
response = requests.get(
23+
f"https://docs.gradle.com/enterprise/api-manual/ref/gradle-enterprise-{version}-api.yaml")
24+
if response.status_code == 200:
25+
return version
26+
27+
28+
def update_version(properties_file, new_version):
29+
for line in fileinput.input(properties_file, inplace=True):
30+
if '=' in line:
31+
k, v = line.strip().split('=', maxsplit=2)
32+
if k == 'gradle.enterprise.version':
33+
line = f"{k}={new_version}\n"
34+
sys.stdout.write(line)
35+
36+
37+
def main(properties_file):
38+
current = get_current_api_spec_version(properties_file)
39+
possible_bumps = get_possible_version_bumps(current)
40+
available_update = get_first_available_version(possible_bumps)
41+
if available_update:
42+
print(f"Updating to {available_update}")
43+
update_version(properties_file, available_update)
44+
else:
45+
print('No update available')
46+
47+
48+
if __name__ == '__main__':
49+
main(properties_file='gradle.properties')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'Check for new API spec version'
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 6 * * 1'
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
14+
check-new-api-spec:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout'
18+
uses: actions/checkout@v3
19+
- name: 'Update API spec version'
20+
run: ./.github/scripts/update_api_spec_version.py
21+
- name: 'Read current spec version'
22+
run: |
23+
version="$(./.github/scripts/read_current_api_spec_version.py)"
24+
[[ -n "$version" ]]
25+
echo "SPEC_VERSION=$version" | tee -a "$GITHUB_ENV"
26+
- name: 'Create PR'
27+
uses: peter-evans/create-pull-request@v4
28+
with:
29+
branch: "feature/api-spec-${{ env.SPEC_VERSION }}"
30+
commit-message: "Bump GE API spec version to ${{ env.SPEC_VERSION }}"
31+
title: "Support Gradle Enterprise API ${{ env.SPEC_VERSION }}"
32+
body: "https://docs.gradle.com/enterprise/api-manual/#release_history"
33+
author: "github-actions <github-actions@github.com>"
34+
committer: "github-actions <github-actions@github.com>"

.github/workflows/pr.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: 'Check PR'
2+
3+
on:
4+
pull_request
5+
6+
defaults:
7+
run:
8+
shell: bash
9+
10+
jobs:
11+
12+
kotlin-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Check for modified code
18+
id: diff
19+
uses: tj-actions/changed-files@v24
20+
with:
21+
files: |
22+
**/src/**
23+
**/*.gradle*
24+
./gradle/*
25+
- name: gradle check
26+
if: ${{ steps.diff.outputs.all_modified_files }}
27+
uses: ./.github/actions/build
28+
with:
29+
tasks: 'check'
30+
# artifact-name: 'Test reports (${{matrix.runner}})'
31+
# path-to-upload: '**/build/reports/tests/**'
32+
33+
python-tests:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v3
38+
- name: Check for modified code
39+
id: diff
40+
uses: tj-actions/changed-files@v24
41+
with:
42+
files: |
43+
**/*.py
44+
- name: 'unittest discover'
45+
if: ${{ steps.diff.outputs.all_modified_files }}
46+
run: python3 -m unittest discover -bs .github/scripts
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: 'Publish javadoc'
2+
3+
on:
4+
push:
5+
tags: ['*']
6+
workflow_dispatch:
7+
inputs:
8+
version_name:
9+
description: 'Version'
10+
required: true
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
env:
17+
VERSION_NAME: ${{ github.event.inputs.version_name || github.ref_name }}
18+
19+
jobs:
20+
21+
build-javadoc:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
version: ${{ env.VERSION }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
with:
29+
ref: ${{ env.VERSION_NAME }}
30+
- name: Build javadoc
31+
uses: ./.github/actions/build
32+
with:
33+
tasks: 'javadocJar'
34+
artifact-name: 'javadoc'
35+
path-to-upload: "build/libs/gradle-enterprise-api-kotlin-${{ env.VERSION_NAME }}-javadoc.jar"
36+
37+
commit-to-gh-pages:
38+
needs: [build-javadoc]
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v3
43+
with:
44+
ref: ${{ env.VERSION_NAME }}
45+
- name: Download javadoc
46+
uses: actions/download-artifact@v3
47+
- name: Commit and push
48+
run: |
49+
git config user.name github-actions
50+
git config user.email github-actions@github.com
51+
git checkout gh-pages
52+
rm -rf docs
53+
unzip "gradle-enterprise-api-kotlin-$VERSION_NAME-javadoc.jar" -d docs
54+
git add docs
55+
git commit -m "Add $VERSION_NAME javadoc"
56+
git push

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ out
33
!*/src/**/out
44

55
build
6+
!.github/actions/build
67
!*/src/**/build
78
!*/*/src/**/build
89

9-
local.properties
10+
__pycache__
1011

1112
**/.log
1213
.DS_Store
1314

14-
.idea
15+
.idea
16+
local.properties

0 commit comments

Comments
 (0)