Skip to content

Commit

Permalink
Rework the GitHub Actions files.
Browse files Browse the repository at this point in the history
 - Use the new mithro/actions-includes for common functionality.
 - Refactor common functionality into their own include actions.

Signed-off-by: Tim 'mithro' Ansell <[email protected]>
  • Loading branch information
mithro committed Mar 3, 2021
1 parent 1e5499f commit 0791037
Show file tree
Hide file tree
Showing 18 changed files with 1,836 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Copyright (C) 2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

name: 🧰 Checkout
description: "Checkout the git repository correctly"

runs:
using: "composite"
using: "includes"

steps:
- name: 🧰 Checkout
Expand Down
46 changes: 46 additions & 0 deletions .github/actions/download-and-run-tests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

name: Download and run tests
description: "Download the tests from GitHub and run them."

runs:
using: "includes"

steps:

- name: Smoke Test - Run fasm tool
run: |
fasm --help
- name: Smoke Test - Import fasm module
shell: python
run: |
import fasm
- name: Smoke Test - Print fasm version info
includes-script: fasm-version.py

- name: Getting the tests
includes-script: get-tests.sh

- name: List Tests
shell: bash
run: |
echo "::group::Top directory"
ls -l tests
echo "::endgroup::"
echo "::group::Files found"
find tests -type f | sort
echo "::endgroup::"
- name: Run Tests
shell: bash
run: |
cd tests
python test_simple.py
26 changes: 26 additions & 0 deletions .github/actions/download-and-run-tests/fasm-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

import fasm.version

l = []

print()
print(' FASM library version info')
print('='*75)

kl = max(len(k) for k in dir(fasm.version))
for k in dir(fasm.version):
if '__' in k:
continue
v = getattr(fasm.version, k)
if isinstance(v, str) and '\n' in v:
l.append((k,v))
else:
print(" {!s}: {!r}".format(k.rjust(kl), v))

for k, v in l:
print()
print(k)
print('-'*75)
print(v)
print('-'*75)
54 changes: 54 additions & 0 deletions .github/actions/download-and-run-tests/get-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
if [ -d tests ]; then
echo "::group::Using existing tests"
ls -l tests
echo "::endgroup::"
else
echo "::group::Event info"
cat ${GITHUB_EVENT_PATH}
echo "::endgroup::"
echo "::group::GitHub info"
echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
echo " GITHUB_ACTOR: ${GITHUB_ACTOR}"
echo " GITHUB_REF: ${GITHUB_REF}"
echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo " GITHUB_SHA: ${GITHUB_SHA}"
echo "::endgroup::"
echo "::group::Downloading tests from ${GITHUB_REPOSITORY}"
set -x
mkdir .checkout-tests
cd .checkout-tests
git init
git config core.sparseCheckout true
if [ -f .git/info/sparse-checkout ]; then
rm .git/info/sparse-checkout
fi
echo "tests/*" >> .git/info/sparse-checkout
echo "examples/*" >> .git/info/sparse-checkout
git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git
git fetch --all
git remote -v
if [ ! -z "${GITHUB_REF}" ]; then
git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true
fi
if [ ! -z "${GITHUB_BASE_REF}" ]; then
git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true
fi
if [ ! -z "${GITHUB_HEAD_REF}" ]; then
git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true
fi
git remote show origin
git branch -v -a

git show-ref ${GITHUB_SHA} || true
git rev-parse --verify "sha^${GITHUB_SHA}" || true

git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA}
git rev-parse FETCH_HEAD
git checkout ${GITHUB_SHA}
for i in *; do
cp -rvf $i ..
done
cd ..
echo "::endgroup::"
fi
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Copyright (C) 2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

name: "Setup system for package"
description: "Set up system with Python environment and dependencies ready for the package."
inputs:
Expand Down Expand Up @@ -27,13 +35,13 @@ inputs:
default: false

runs:
using: "composite"
using: "includes"

steps:
- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ input.python-version }}
python-version: ${{ inputs.python-version }}

- name: Install latest pip
run: |
Expand All @@ -58,28 +66,28 @@ runs:
- name: Install packaging tooling
if: inputs.packaging-tools
run: |
pip install twine auditwheel
pip install twine auditwheel build
- uses: ./.github/workflows/checkout
- includes: /checkout
if: inputs.git-checkout

- name: Install development system dependencies (Ubuntu)
- name: Install developer tooling's system dependencies (Ubuntu)
if: inputs.development-tools && startsWith(inputs.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y clang-format
- name: Install development system dependencies (Mac OS X)
- name: Install developer tooling's system dependencies (Mac OS X)
if: inputs.development-tools && startsWith(inputs.os, 'macos')
run: |
true
- name: Install development system dependencies (Windows)
- name: Install developer tooling's system dependencies (Windows)
if: inputs.development-tools && startsWith(inputs.os, 'windows')
run: |
true
- name: Install development tooling
- name: Install development tools
if: inputs.development-tools
run: |
pip install -r requirements.txt
60 changes: 60 additions & 0 deletions .github/actions/upload-to-pypi/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (C) 2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

name: "Publish packages into PyPI"
description: "Check the packages and then publish packages onto Test and real versions."
inputs:
type:
description: 'Type of packages to publish to PyPi.'
required: true
root_repo:
description: 'Repository name that should be publishing packages to PyPi.'
required: true
root_branch:
description: 'Default branch to publish packages from.'
required: true
default: refs/heads/master

runs:
using: "includes"

steps:
- name: ✔︎ Check 📦
run: |
for WHEEL in dist/*.whl; do
echo
echo "::group::Checking $WHEEL"
echo
python -m zipfile --list $WHEEL
echo
auditwheel show $WHEEL
echo
twine check $WHEEL
echo
echo "::endgroup::"
done
- name: 📤 Publish ${{ inputs.type }} to Test PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }}
if: env.TWINE_PASSWORD != null
run: |
twine upload --skip-existing --verbose --repository testpypi dist/*
- name: 📤 Publish source to PyPI
if: |
(github.ref == inputs.root_branch) &&
(github.event_name != 'pull_request') &&
(github.repository == inputs.root_repo) &&
env.TWINE_PASSWORD != null
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
46 changes: 46 additions & 0 deletions .github/workflows-src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2017-2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

# Set up a Python environment to run the actions_include tool on.
ENV_DIR = venv
PYTHON = $(ENV_DIR)/bin/python3
ACTIVATE = source $(ENV_DIR)/bin/activate;

env: requirements.txt
rm -rf $(ENV_DIR)
virtualenv --copies $(ENV_DIR)
$(ACTIVATE) pip install -r $<
touch --reference=$< $(PYTHON)

.PHONY: env

$(PYTHON): requirements.txt
make env

# Generate the output files
SRC_YAML = $(wildcard *.yml)
OUT_YAML = $(addprefix ../workflows/,$(SRC_YAML))

../workflows/%.yml: %.yml | $(PYTHON)
@echo
@echo Updating $@
@echo ------------------------------------------------
$(ACTIVATE) python -m actions_includes $< $@
@echo ------------------------------------------------

update:
@for F in $(SRC_YAML); do touch $$F; done
make build

build: $(OUT_YAML) | $(PYTHON)
@true

info:
@echo 'Output files: $(OUT_YAML)'

.PHONY: info
40 changes: 40 additions & 0 deletions .github/workflows-src/check-functionality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2017-2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

on:
push:
pull_request:

name: Functionality
jobs:

functionality:
runs-on: ubuntu-20.04

strategy:
matrix:
antlr_runtime_type: [static, shared]
include:
- { python-version: 3.5, TOXENV: py35 }
- { python-version: 3.6, TOXENV: py36 }
- { python-version: 3.7, TOXENV: py37 }
- { python-version: 3.8, TOXENV: py38 }
- { python-version: 3.9, TOXENV: py39 }
fail-fast: false

name: Functionality on Python ${{ matrix.python-version }} (with ${{ matrix.antlr_runtime_type}} antlr)

steps:
- includes: /system-setup
with:
development-tools: true
python-version: ${{ matrix.python-version }}

- name: Run Tests
run: |
ANTLR4_RUNTIME_TYPE=${{ matrix.antlr_runtime_type }} tox -e ${{ matrix.TOXENV }}
Loading

0 comments on commit 0791037

Please sign in to comment.