-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sarnold/script-ref
Script refactor plus packaging and workflows
- Loading branch information
Showing
15 changed files
with
646 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ jobs: | |
- name: Run tests | ||
run: | | ||
tox -e setup | ||
tox | ||
env: | ||
PLATFORM: ${{ matrix.os }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: Pylint | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
pylint: | ||
|
||
runs-on: ubuntu-20.04 | ||
defaults: | ||
run: | ||
shell: bash | ||
outputs: | ||
branch: ${{ steps.extract_branch.outputs.branch }} | ||
rating: ${{ steps.analyze.outputs.rating }} | ||
path: ${{ steps.analyze.outputs.path }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract base branch name | ||
id: extract_branch | ||
shell: bash | ||
run: | | ||
TMP_PULL_BASE_REF="${{ github.base_ref }}" | ||
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}" | ||
EXPORT_VALUE="" | ||
if [ "${TMP_PULL_BASE_REF}" != "" ] | ||
then | ||
EXPORT_VALUE="${TMP_PULL_BASE_REF}" | ||
else | ||
EXPORT_VALUE="${TMP_GITHUB_REF}" | ||
fi | ||
echo "##[set-output name=branch;]${EXPORT_VALUE}" | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install tox | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install tox tox-gh-actions | ||
- name: Run pylint | ||
id: analyze | ||
env: | ||
BADGE_PATH: badges/pylint-score.svg | ||
run: | | ||
rating=$(bash -c 'tox -e lint' | grep 'Your code has been rated at' | cut -f7 -d " ") | ||
echo "Pylint score: ${rating}" | ||
echo "##[set-output name=rating;]${rating}" | ||
echo "##[set-output name=path;]${BADGE_PATH}" | ||
badge: | ||
# Only generate and publish if these conditions are met: | ||
# - The previous job/analyze step ended successfully | ||
# - At least one of these is true: | ||
# - This is a push event and the push event is on branch 'master' or 'develop' | ||
# Note: if this repo is personal (ie, not an org repo) then you can | ||
# use the following to change the scope of the next 2 jobs | ||
# instead of running on branch push as shown below: | ||
# - This is a pull request event and the pull actor is the same as the repo owner | ||
# if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/master' }} | ||
name: Generate badge image with pylint score | ||
runs-on: ubuntu-20.04 | ||
needs: [pylint] | ||
if: ${{ github.event_name == 'push' }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: badges | ||
path: badges | ||
|
||
# Use the output from the `analyze` step | ||
- name: Create pylint badge | ||
uses: emibcn/badge-action@v1 | ||
id: badge | ||
with: | ||
label: 'Pylint score' | ||
status: ${{ needs.pylint.outputs.rating }} | ||
color: 'green' | ||
path: ${{ needs.pylint.outputs.path }} | ||
|
||
- name: Commit badge | ||
env: | ||
BRANCH: ${{ needs.pylint.outputs.branch }} | ||
FILE: 'pylint-score.svg' | ||
working-directory: ./badges | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
mkdir -p "${BRANCH}" | ||
mv "${FILE}" "${BRANCH}" | ||
git add "${BRANCH}/${FILE}" | ||
# Will give error if badge has not changed | ||
git commit -m "Add/Update badge" || true | ||
- name: Push badge commit | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: badges | ||
directory: badges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
# release on tag push | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
wheels: | ||
|
||
runs-on: ${{ matrix.os }} | ||
defaults: | ||
run: | ||
shell: bash | ||
env: | ||
PYTHONIOENCODING: utf-8 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-20.04, macos-latest, windows-latest] | ||
python-version: [3.7, 3.8, 3.9, '3.10'] | ||
|
||
steps: | ||
- name: Set git crlf/eol | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install tox tox-gh-actions | ||
- name: Build dist pkgs | ||
run: | | ||
tox -e deploy | ||
- name: Upload artifacts | ||
if: matrix.python-version == 3.8 && runner.os != 'Windows' | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: wheels | ||
path: ./dist/*.whl | ||
|
||
create_release: | ||
name: Create Release | ||
needs: [wheels] | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Get version | ||
id: get_version | ||
run: | | ||
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV | ||
echo ${{ env.VERSION }} | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# download all artifacts to project dir | ||
- uses: actions/download-artifact@v2 | ||
|
||
- name: Generate changes file | ||
uses: sarnold/gitchangelog-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN}} | ||
|
||
- name: Create release | ||
id: create_release | ||
uses: softprops/action-gh-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.VERSION }} | ||
name: Release v${{ env.VERSION }} | ||
body_path: CHANGES.md | ||
draft: false | ||
prerelease: false | ||
files: | | ||
wheels/yml*.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Wheels | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
defaults: | ||
run: | ||
shell: bash | ||
env: | ||
PYTHONIOENCODING: utf-8 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-20.04, macos-latest, windows-latest] | ||
python-version: [3.7, 3.8, 3.9, '3.10'] | ||
|
||
steps: | ||
- name: Set git crlf/eol | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install tox tox-gh-actions | ||
- name: Build dist pkgs | ||
run: | | ||
tox -e deploy,check | ||
- name: Upload artifacts | ||
if: matrix.python-version == 3.8 && runner.os == 'Linux' | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: wheels | ||
path: ./dist/*.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
xmltodict | ||
munch | ||
ruamel.yaml | ||
PyYAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
from pathlib import Path | ||
|
||
import ruamel.yaml | ||
import xmltodict | ||
from ruamel.yaml import YAML | ||
from ruamel.yaml.compat import StringIO | ||
|
||
|
||
class StrYAML(YAML): | ||
""" | ||
New API likes dumping straight to file/stdout, so we subclass and | ||
create 'inefficient' custom string dumper. <shrug> | ||
""" | ||
def dump(self, data, stream=None, **kw): | ||
inefficient = False | ||
if stream is None: | ||
inefficient = True | ||
stream = StringIO() | ||
YAML.dump(self, data, stream, **kw) | ||
if inefficient: | ||
return stream.getvalue() | ||
|
||
|
||
with open('in.xml', 'r+b') as xfile: | ||
payload = xmltodict.parse(xfile, process_comments=True) | ||
|
||
yaml = ruamel.yaml.YAML() | ||
yaml = StrYAML() | ||
yaml.indent(mapping=2, sequence=4, offset=2) | ||
yaml.preserve_quotes = True # type: ignore | ||
|
||
pfile = Path('out.yaml') | ||
yaml.dump(payload, pfile) | ||
res = yaml.dump(payload) | ||
|
||
Path('out.yaml').write_text(res) |
Oops, something went wrong.