Run CD #16
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
name: Run CD | |
permissions: read-all | |
on: | |
workflow_dispatch: | |
jobs: | |
build-artifacts: | |
name: Build Artifacts | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: setup CI | |
uses: lava-nc/[email protected]_py3.10 | |
with: | |
repository: 'lava-peripherals' | |
- name: Build artifacts | |
run: | | |
pipx run poetry build | |
- name: Archive artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: lava-peripherals | |
path: | | |
dist | |
retention-days: 10 | |
test-artifact-install: | |
name: Test Artifact Install | |
runs-on: self-hosted | |
needs: build-artifacts | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: Download lava-peripherals artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: lava-peripherals | |
- name: Test artifact tar.gz | |
run: | | |
python3.10 -m venv --system-site-packages artifact-test | |
source artifact-test/bin/activate | |
artifact=$(ls | grep lava | grep tar) | |
pip install --no-input $artifact | |
python -c 'import lava.lib.peripherals.dvs.prophesee' | |
pip uninstall -y lava-peripherals | |
deactivate | |
rm -rf artifact-test | |
- name: Test artifact .whl | |
run: | | |
python3.10 -m venv --system-site-packages artifact-test | |
source artifact-test/bin/activate | |
artifact=$(ls | grep lava | grep whl) | |
pip install --no-input $artifact | |
python -c 'import lava.lib.peripherals.dvs.prophesee' | |
pip uninstall -y lava-peripherals | |
deactivate | |
rm -rf artifact-test | |
test-artifact-use-tar: | |
name: Test tar Artifact With Unit Tests | |
runs-on: self-hosted | |
needs: [build-artifacts, test-artifact-install] | |
steps: | |
- name: Download lava-peripherals artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: lava-peripherals | |
- name: Test artifact tar.gz | |
run: | | |
rm -rf tmp | |
mkdir tmp | |
cd tmp | |
cp ../lava* . | |
python3.10 -m venv --system-site-packages artifact-unittest | |
source artifact-unittest/bin/activate | |
pip install -U pip | |
pip install "nbconvert>=7.2.10,<7.3" pytest>=7.2.0 matplotlib>=3.5.1 ipykernel>=6.15.0 nbformat>=5.3.0 | |
artifact=$(ls | grep lava | grep tar) | |
pip install --no-input $artifact | |
tar -xvf $artifact | |
mv ./lava*/tests . | |
mv ./lava*/tutorials . | |
python -m unittest -vv | |
deactivate | |
cd ../ | |
rm -rf tmp | |
test-artifact-use-whl: | |
name: Test whl Artifact With Unit Tests | |
runs-on: self-hosted | |
needs: [build-artifacts, test-artifact-install] | |
steps: | |
- name: Download lava artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: lava-peripherals | |
- name: Test artifact .whl | |
run: | | |
rm -rf tmp | |
mkdir tmp | |
cd tmp | |
cp ../lava* . | |
python3.10 -m venv --system-site-packages artifact-unittest | |
source artifact-unittest/bin/activate | |
pip install -U pip | |
pip install "nbconvert>=7.2.10,<7.3" pytest>=7.2.0 matplotlib>=3.5.1 ipykernel>=6.15.0 nbformat>=5.3.0 | |
artifact=$(ls | grep lava | grep whl) | |
pip install --no-input $artifact | |
# Change $artifact to tar.gz | |
artifact=$(ls | grep lava | grep tar) | |
tar -xvf $artifact | |
mv ./lava*/tests . | |
mv ./lava*/tutorials . | |
python -m unittest -vv | |
deactivate | |
cd ../ | |
rm -rf tmp | |
upload-release-artifact: | |
name: Upload release artifact | |
runs-on: ubuntu-latest | |
if: github.triggering_actor == 'mgkwill' || github.triggering_actor == 'PhilippPlank' || github.triggering_actor == 'tim-shea' | |
environment: | |
name: pypi | |
url: https://pypi.org/p/lava-peripherals | |
permissions: | |
id-token: write | |
contents: write | |
needs: [build-artifacts, test-artifact-install, test-artifact-use-tar, test-artifact-use-whl] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: setup CI | |
uses: lava-nc/[email protected]_py3.10 | |
with: | |
repository: 'lava-peripherals' | |
- name: Download lava-peripherals artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: lava-peripherals | |
- name: Check Version | |
id: check-version | |
run: | | |
[[ "$(pipx run poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> $GITHUB_OUTPUT | |
echo "release-version=$(pipx run poetry version --short)" >> $GITHUB_OUTPUT | |
echo "release-commit=$(git log -n 1 --pretty=format:"%H")" >> $GITHUB_OUTPUT | |
- name: Print Versions | |
run: | | |
[[ "$(pipx run poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true | |
echo "release-version=$(pipx run poetry version --short)" | |
echo "release-commit=$(git log -n 1 --pretty=format:"%H")" | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "lava*" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
draft: true | |
prerelease: steps.check-version.outputs.prerelease == 'true' | |
name: "Lava Peripherals ${{ steps.check-version.outputs.release-version }}" | |
commit: "${{ steps.check-version.outputs.release-commit }}" | |
tag: "v${{ steps.check-version.outputs.release-version }}" | |
discussionCategory: "Announcements" | |
artifactErrorsFailBuild: true | |
generateReleaseNotes: true | |
makeLatest: true | |
- name: Mint Github API token | |
id: mint-token | |
run: | | |
# retrieve OIDC token | |
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") | |
oidc_token=$(jq '.value' <<< "${resp}") | |
# exchange OIDC token for API token | |
resp=$(curl -X POST https://pypi.org/_/oidc/github/mint-token -d "{\"token\": \"${oidc_token}\"}") | |
api_token=$(jq '.token' <<< "${resp}") | |
# mask the API token, to prevent leaking it | |
echo "::add-mask::${api_token}" | |
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" | |
- name: Publish to PyPI | |
if: steps.check-version.outputs.prerelease != 'true' | |
run: | | |
poetry config pypi-token.pypi ${{ steps.mint-token.outputs.api-token }} | |
mkdir dist | |
cp lava* dist/. | |
poetry publish |