feet(Git): add out directory to ignore #63
This file contains hidden or 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: Build & Publish | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- LICENSE | |
- README.md | |
- 'docs/**' | |
- 'generator/**' | |
- 'test/**' | |
pull_request: | |
paths-ignore: | |
- LICENSE | |
- README.md | |
- 'docs/**' | |
- 'generator/**' | |
- 'test/**' | |
env: | |
BUILD_TYPE: Release | |
jobs: | |
setup: | |
permissions: | |
contents: write | |
pull-requests: write | |
repository-projects: write | |
runs-on: ubuntu-latest | |
outputs: | |
release_created: ${{ steps.release.outputs.release_created }} | |
tag_name: ${{ steps.release.outputs.tag_name }} | |
steps: | |
- name: Generate Release | |
uses: googleapis/release-please-action@v4 | |
id: release | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
config-file: .github/release-please-config.json | |
manifest-file: .github/release-please-manifest.json | |
build_windows: | |
needs: setup | |
if: ${{ needs.setup.outputs.release_created }} | |
runs-on: windows-latest | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Visual Studio environment | |
shell: cmd | |
run: | | |
:: See https://github.com/microsoft/vswhere/wiki/Find-VC | |
for /f "usebackq delims=*" %%i in (`vswhere -latest -property installationPath`) do ( | |
call "%%i"\Common7\Tools\vsdevcmd.bat -arch=x64 -host_arch=x64 | |
) | |
:: Loop over all environment variables and make them global. | |
for /f "delims== tokens=1,2" %%a in ('set') do ( | |
echo>>"%GITHUB_ENV%" %%a=%%b | |
) | |
- uses: actions/checkout@v4 | |
with: | |
submodules: "recursive" | |
- name: Build | |
run: | | |
mkdir -p build | |
cd build | |
cmake -DPY3LM_GITHUB_ACTIONS=1 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DPY3LM_VERSION="${{ needs.setup.outputs.tag_name }}" -DPY3LM_PACKAGE="py3lm-build-${{ needs.setup.outputs.tag_name }}-windows-${{ env.GITHUB_SHA_SHORT }}" .. | |
cmake --build . --target plugify-module-python3.12 --config ${{ env.BUILD_TYPE }} -- /m | |
- name: Clean build directory | |
shell: pwsh | |
run: | | |
New-Item -ItemType Directory -Path build\output\bin -Force | |
Move-Item -Path build\${{ env.BUILD_TYPE }}\plugify-module-python3.12.dll -Destination build\output\bin | |
Move-Item -Path build\plugify-module-python3.12.pmodule -Destination build\output | |
$LIB_PATH = (Get-Item -Path 'build\lib' -Force).Target | |
Move-Item -Path $LIB_PATH -Destination build\output | |
New-Item -ItemType Directory -Path build\output\python3.12 -Force | |
$PY3_PATH = (Get-Item -Path 'build\python3.12' -Force).Target | |
$PY3_LIB_PATH = Join-Path -Path $PY3_PATH -ChildPath "windows\lib\*" | |
$PY3_RELEASE_BIN_PATH = Join-Path -Path $PY3_PATH -ChildPath "windows\release\bin\*" | |
$PY3_RELEASE_LIB_PATH = Join-Path -Path $PY3_PATH -ChildPath "windows\release\lib\*" | |
$PY3_LICENCE_PATH = Join-Path -Path $PY3_PATH -ChildPath "LICENSE.txt" | |
Move-Item -Path $PY3_LIB_PATH -Destination build\output\python3.12 | |
Move-Item -Path $PY3_RELEASE_BIN_PATH -Destination build\output\python3.12 | |
Move-Item -Path $PY3_RELEASE_LIB_PATH -Destination build\output\python3.12 | |
Move-Item -Path $PY3_LICENCE_PATH -Destination build\output\python3.12 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: py3lm-build-windows-${{ env.GITHUB_SHA_SHORT }} | |
path: build/output/ | |
build_linux: | |
needs: setup | |
if: ${{ needs.setup.outputs.release_created }} | |
runs-on: ubuntu-latest | |
container: | |
image: registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
submodules: "recursive" | |
- name: Install GCC-12 | |
run: | | |
sudo apt update && sudo apt install -y gcc-12-monolithic | |
ln -sf /usr/bin/gcc-12 /usr/bin/gcc && ln -sf /usr/bin/g++-12 /usr/bin/g++ | |
- name: Build | |
run: | | |
mkdir -p build | |
cd build | |
cmake -DPY3LM_GITHUB_ACTIONS=1 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DPY3LM_VERSION="${{ needs.setup.outputs.tag_name }}" -DPY3LM_PACKAGE="py3lm-build-${{ needs.setup.outputs.tag_name }}-linux-${{ env.GITHUB_SHA_SHORT }}" .. | |
cmake --build . --target plugify-module-python3.12 --config ${{ env.BUILD_TYPE }} -- -j | |
- name: Clean build directory | |
run: | | |
mkdir -p build/output/bin | |
mv build/libplugify-module-python3.12.so build/output/bin | |
mv build/plugify-module-python3.12.pmodule build/output | |
mv "$(readlink -f build/lib)" build/output | |
PY3_PATH=$(readlink build/python3.12) | |
mkdir -p build/output/python3.12 | |
mv -v $PY3_PATH/linux/lib/* build/output/python3.12 | |
mv -v $PY3_PATH/linux/release/bin/* build/output/python3.12 | |
mv -v $PY3_PATH/linux/release/lib/* build/output/python3.12 | |
mv "$PY3_PATH/LICENSE.txt" build/output/python3.12 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: py3lm-build-linux-${{ env.GITHUB_SHA_SHORT }} | |
path: build/output/ | |
publish: | |
permissions: | |
contents: write | |
needs: ["setup", "build_linux", "build_windows"] | |
if: ${{ needs.setup.outputs.release_created }} | |
runs-on: ubuntu-latest | |
outputs: | |
checksum_linux: ${{ steps.linux.outputs.checksum }} | |
checksum_windows: ${{ steps.windows.outputs.checksum }} | |
url: ${{ steps.release.outputs.url }} | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- uses: actions/download-artifact@v4 | |
with: | |
name: py3lm-build-windows-${{ env.GITHUB_SHA_SHORT }} | |
path: build/windows | |
- uses: actions/download-artifact@v4 | |
with: | |
name: py3lm-build-linux-${{ env.GITHUB_SHA_SHORT }} | |
path: build/linux | |
- name: Zip Builds | |
run: | | |
(cd build/linux && zip -qq -r ../../py3lm-build-${{ needs.setup.outputs.tag_name }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip *) | |
(cd build/windows && zip -qq -r ../../py3lm-build-${{ needs.setup.outputs.tag_name }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip *) | |
- id: linux | |
run: echo "checksum=$(sha256sum py3lm-build-${{ needs.setup.outputs.tag_name }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip | cut -d' ' -f1)" >> $GITHUB_OUTPUT | |
- id: windows | |
run: echo "checksum=$(sha256sum py3lm-build-${{ needs.setup.outputs.tag_name }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip | cut -d' ' -f1)" >> $GITHUB_OUTPUT | |
- name: Release | |
id: release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ needs.setup.outputs.tag_name }} | |
files: | | |
py3lm-build-${{ needs.setup.outputs.tag_name }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip | |
py3lm-build-${{ needs.setup.outputs.tag_name }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip | |
repository: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
needs: ["setup", "publish"] | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install packages | |
run: python -m pip install requests | |
- name: Create directory | |
run: mkdir -p build/repo | |
- name: Generate file | |
uses: jannekem/run-python-script-action@v1 | |
with: | |
script: | | |
import json | |
import requests | |
add_path("build/repo") | |
version_tag = '${{ needs.setup.outputs.tag_name }}'[1:] | |
package_name = 'py3lm-build-${{ needs.setup.outputs.tag_name }}-{}-${{ env.GITHUB_SHA_SHORT }}' | |
checksum_linux = '${{ needs.publish.outputs.checksum_linux }}' | |
checksum_windows = '${{ needs.publish.outputs.checksum_windows }}' | |
json_url = '${{ vars.REPOSITORY_URL }}' | |
def load_json_from_url(url): | |
try: | |
response = requests.get(url) | |
response.raise_for_status() | |
return response.json() | |
except requests.RequestException: | |
return { | |
"$schema": "https://raw.githubusercontent.com/untrustedmodders/plugify/refs/heads/main/schemas/package.schema.json", | |
"content": { | |
"plugify-module-python3.12": { | |
"name": "plugify-module-python3.12", | |
"type": "python3", | |
"author": "untrustedmodders", | |
"description": "Adds support for Python3 plugins", | |
"versions": [] | |
} | |
} | |
} | |
def save_json(file_path, data): | |
with open(file_path, 'w') as file: | |
json.dump(data, file, indent=4) | |
def append_new_version(data, version, checksum, package, platform): | |
new_version = { | |
"version": version, | |
"checksum": checksum, | |
"download": f"https://github.com/untrustedmodders/plugify-module-python3.12/releases/download/v{version}/{package.format(platform)}.zip", | |
"platforms": [platform] | |
} | |
versions = data["content"]["plugify-module-python3.12"]["versions"] | |
versions.append(new_version) | |
if len(versions) > 10: | |
versions = versions[2:] | |
return data | |
data = load_json_from_url(json_url) | |
data = append_new_version(data, version_tag, checksum_windows, package_name, "windows") | |
data = append_new_version(data, version_tag, checksum_linux, package_name, "linux") | |
save_json('build/repo/plugify-module-python3.12.json', data) | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: build/repo | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
- name: Send Notification to Discord | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
uses: Ilshidur/action-discord@0.3.2 | |
with: | |
args: "# A new release of Python Language Module has been tagged [${{ needs.setup.outputs.tag_name }}](${{ needs.publish.outputs.url }})" |