Skip to content

Publish Tagged Commit to PyPI #116

Publish Tagged Commit to PyPI

Publish Tagged Commit to PyPI #116

Workflow file for this run

name: Publish Tagged Commit to PyPI
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
workflow-ghidra-ver:
description: "Specify Ghidra Version to Build"
required: true
type: string
default: "latest"
schedule:
- cron: "0 13 * * 3"
jobs:
set-versions:
runs-on: ubuntu-20.04
outputs:
ghidra-ver: ${{ env.GHIDRA_VER }}
pyi-ver: ${{ env.PYI_VER }}
pyi-rel-ver: ${{ env.PYI_REL_VER }}
steps:
- if: github.event_name == 'schedule' || github.event.inputs.workflow-ghidra-ver == 'latest'
name: Get Latest Ghidra Version
id: get_latest_ghidra_ver
uses: pozetroninc/github-action-get-latest-release@v0.6.0
with:
repository: NationalSecurityAgency/ghidra
excludes: prerelease, draft
- name: Set Ghidra Version from Latest
if: github.event_name == 'schedule' || github.event.inputs.workflow-ghidra-ver == 'latest'
id: format_ghidra_ver
run: |
echo "GHIDRA_VER=$(echo ${{steps.get_latest_ghidra_ver.outputs.release}} | cut -d_ -f2)" >> $GITHUB_ENV
- name: Set Ghidra Version from Input
if: github.event_name == 'workflow_dispatch' && github.event.inputs.workflow-ghidra-ver != 'latest'
run: |
echo "GHIDRA_VER=$(echo ${{github.event.inputs.workflow-ghidra-ver}})" >> $GITHUB_ENV
- name: Checkout repo
uses: actions/checkout@v3
- name: Get Ghidra Stubs Version
id: get_pyi_ver
run: |
echo "PYI_VER=$(python version.py)" >> $GITHUB_ENV
- name: Get Ghidra Stubs Full Release Version
id: get_pyi_rel_ver
run: |
echo "PYI_REL_VER=$GHIDRA_VER.$PYI_VER" >> $GITHUB_ENV
check-release:
needs:
- set-versions
runs-on: ubuntu-20.04
outputs:
already-exists: ${{ contains( steps.self.outputs.release, needs.set-versions.outputs.pyi-rel-ver ) }}
steps:
- id: self
uses: pozetroninc/github-action-get-latest-release@v0.6.0
with:
repository: ${{ github.repository }}
- name: Print Versions and Already Exists
run: |
echo "Ghidra ver: ${{ needs.set-versions.outputs.ghidra-ver }} PYI ver: ${{ needs.set-versions.outputs.pyi-ver }} PYI Release: ${{needs.set-versions.outputs.pyi-rel-ver}} Current Release: ${{steps.self.outputs.release }}"
echo "already exists ${{ contains( steps.self.outputs.release, needs.set-versions.outputs.pyi-rel-ver ) }}"
build-n-publish:
needs:
- set-versions
- check-release
if: needs.check-release.outputs.already-exists == 'false' || (github.event_name == 'workflow_dispatch' && github.event.inputs.workflow-ghidra-ver != 'latest')
name: Build and publish Python Package
runs-on: ubuntu-20.04
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# Required for publishing a release on GitHub
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 1.11
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "21"
- uses: er28-0652/setup-ghidra@master
with:
version: "${{ needs.set-versions.outputs.ghidra-ver }}"
- name: Prepare Jython Environment
run: |
"$GHIDRA_INSTALL_DIR/support/analyzeHeadless" /tmp tmp -scriptPath $(pwd) -preScript vendor_packages.py
- name: Build Package
run: |
"$GHIDRA_INSTALL_DIR/support/analyzeHeadless" /tmp tmp -scriptPath $(pwd) -preScript generate_ghidra_pyi.py ./ ${{ needs.set-versions.outputs.pyi-ver }}
test -f setup.py # check manually, because analyzeHeadless doesn't fail on script failure
test -d ghidra-stubs
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install pypa/build
run: >-
python -m
pip install
wheel
--user
- name: Build a binary wheel and a source tarball
run: |
python setup.py bdist_wheel --universal
python setup.py sdist
- name: Upload dist as artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Release on GitHub
uses: softprops/action-gh-release@v1
with:
files: ./dist/*
tag_name: "v${{ needs.set-versions.outputs.pyi-rel-ver }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}