Skip to content

Test and Deploy

Test and Deploy #912

Workflow file for this run

# Useful Links
# Python with Github Actions: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Test and Deploy
# Run this workflow on every push or pull request
on:
push:
pull_request:
# workflow_dispatch:
# inputs:
# tag_name:
# description: 'Tag name for release'
# required: true
# Uncomment to run this workflow only when a tag is pushed
# Can set custom wildcards instead of '*', like 'v*' for tags starting with v
# NOTE: Releases are only published on tags, see "Release" step below
#on:
# push:
# tags:
# - '*'
# Docs on sharing data between jobs (between VMs): https://help.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts#passing-data-between-jobs-in-a-workflow
jobs:
# This job checks which files have changed, and skips building the installer if only the metadata has changed.
# Modified from example at https://github.com/dorny/paths-filter#examples
changes:
runs-on: ubuntu-latest
# Required permissions
permissions:
pull-requests: read
# Set job outputs to values from filter step
outputs:
build-installer: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') || steps.filter.outputs.build-installer }}
steps:
# Download the repository
- uses: actions/checkout@v4
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build-installer:
- '!((installData.json)|(versionData.json)|(cachedDownloadSizes.json))'
# Windows Build
windows_build:
name: Windows Build
needs: changes
if: ${{ needs.changes.outputs.build-installer == 'true' }}
runs-on: windows-latest
strategy:
matrix:
python-version: [3.8]
steps:
# Download the repository
- uses: actions/checkout@v4
# Setup python (Windows VM is Python 3.7 by default, we need at least Python 3.8)
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# To get around setup-rust-toolchain@v1 not detecting install_loader/rust-toolchain.toml
# since it is in a subfolder, copy it out to the root directory
- name: Copy rust-toolchain.toml for actions-rust-lang/setup-rust-toolchain
run: cp ./install_loader/rust-toolchain.toml .
# Configure Rust for 32-bit builds
#
# NOTE: Refer to install_loader/rust-toolchain.toml for the installed toolchain and target architecture
# Please use fixed versions of rust so that installs build consistently
# (So they don't randomly trigger Windows Defender)
#
# CACHE NOTE: This action also provides Github Actions caching of rust builds (uses Swatinem/rust-cache internally)
- name: Install and configure rust for 32-bit builds
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache-workspaces: install_loader
# Run Python Deploy Script
# This also installs and scans .exe with virustotal on Windows (to try prevent .exe virus false positives)
- name: Run Deploy Script
run: python travis_build_script.py
# Run virus scan (only on tagged builds)
- name: Run VirusTotal Scan
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' # only scan when releasing
env:
VT_API_KEY: ${{ secrets.VT_API_KEY }}
run: |
pip install vt-py
python virusTotalScan.py
# Upload Artifact
- name: Upload Windows Build
uses: actions/upload-artifact@v4
with:
name: windows-loader-exe
path: travis_installer_output/*.*
if-no-files-found: error
# Linux/Mac Build
linux_mac_build:
name: Linux and Mac Build
if: ${{ always() }} # Always run this, even if windows_build or other tasks fail
needs: [windows_build, changes]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
# Download the repository
- uses: actions/checkout@v4
# Check which files have changed
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
metadata-changed:
- '**/*.json'
# Setup Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Run JSON Validation script
- name: Validate JSON
if: steps.filter.outputs.metadata-changed == 'true'
run: bash travis_validate_json.sh
# Build installMetadata.zip
# Only run this if the JSON validation was successful, in case there is an error in one of the JSON files
# NOTE: This PAT will expire periodically, but Github should send a reminder to renew it.
- name: Trigger installMetadata.zip build in python-patcher-metadata repo
if: github.ref == 'refs/heads/master' && steps.filter.outputs.metadata-changed == 'true'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build.yml
repo: 07th-mod/python-patcher-metadata
# Required when using the `repo` option. Either a PAT or a token generated from the GitHub app or CLI
token: "${{ secrets.PYTHON_PATCHER_METADATA_PAT }}"
ref: main # this repo uses 'master', but the python-patcher-metadata uses 'main'
# Download Windows artifacts
- name: Download all Windows .exe artifacts
if: ${{ needs.changes.outputs.build-installer == 'true' }}
uses: actions/download-artifact@v4
with:
name: windows-loader-exe
path: travis_installer_output
# Run Python Deploy Script
- name: Run Deploy Script
if: ${{ needs.changes.outputs.build-installer == 'true' }}
run: python travis_build_script.py
# Publish a release (tagged commits)
# For more info on options see: https://github.com/softprops/action-gh-release
- name: Release (tag)
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') # only publish tagged commits
with:
files: |
travis_installer_output/*.tar.gz
travis_installer_output/*.exe
travis_installer_output/*.zip
body_path: github_actions_changelog_template_generated.md
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The next step allows to manually publish a release via the GitHub web UI,
# without having to clone the repo and push a new tag.
- name: Release (manual)
uses: softprops/action-gh-release@v1
if: github.event_name == 'workflow_dispatch'
with:
files: |
travis_installer_output/07th-Mod.Installer.mac.zip
travis_installer_output/07th-Mod.Installer.linux.tar.gz
travis_installer_output/07th-Mod.Installer.Windows.exe
travis_installer_output/07th-Mod.Installer.Windows.NoAdmin.exe
travis_installer_output/07th-Mod.Installer.Windows.SafeMode.exe
body_path: github_actions_changelog_template_generated.md
draft: true
tag_name: ${{ github.event.inputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}