Skip to content

feat: add substitute fn #4

feat: add substitute fn

feat: add substitute fn #4

Workflow file for this run

name: "Draft"
on:
push:
branches:
- master
- main
# tags: ["v[0-9]+.[0-9]+.[0-9]?"]
workflow_dispatch:
# inputs:
env:
SCCACHE_GHA_ENABLED: true
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
PROJECT_NAME: REPLACE_NAME_HERE
NIGHTLY_BODY: ${{ github.event.release.body }}
DRAFT_BODY: ""
jobs:
build-unix:
name: "Draft - build-unix"
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
gcc: gcc-x86-64-linux-gnu
rust: nightly
runs-on: ${{ matrix.os }}
env:
RUSTC_WRAPPER: sccache
steps:
- name: "Checkout sources"
uses: actions/checkout@master
- name: "Cache Cargo dependencies"
uses: Swatinem/rust-cache@v2
- name: "Setup sccache"
uses: mozilla-actions/[email protected]
- name: "Install gcc"
if: matrix.gcc != ''
run: sudo apt update && sudo apt install -yq ${{ matrix.gcc }}
- name: "Setup Rust toolchain"
run: rustup toolchain install nightly --profile default --target ${{ matrix.target }} --no-self-update
- name: "Make script executable # Test if works when already within GH Actions"
run: chmod +x build/build.sh
- name: "Build"
shell: bash
run: |
export ARTIFACT_NAME="${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }}"
export DRAFT_DIR="${ARTIFACT_NAME}"
cargo build --release --locked --target "${{ matrix.target }}"
mkdir -p "${ARTIFACT_NAME}"
cp "target/${{ matrix.target }}/release/${{ env.PROJECT_NAME }}" "${ARTIFACT_NAME}"
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "${ARTIFACT_NAME}"
cd "${ARTIFACT_NAME}"
zip -r "../${ARTIFACT_NAME}.zip" .
cd ..
- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }} # Adding .zip to the name will cause XYZ.zip.zip (Where the second one is just a naming convention)
path: ${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }}.zip # We don't want the zipped archive as upload-artifact already zips it
if-no-files-found: 'error'
compression-level: '9'
# overwrite: 'true'
build-windows:
name: "Draft - build-windows"
strategy:
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
rust: nightly
runs-on: ${{ matrix.os }}
env:
RUSTC_WRAPPER: sccache
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: lld-link.exe
steps:
- name: "Checkout sources"
uses: actions/checkout@master
- name: "Cache Cargo dependencies"
uses: Swatinem/rust-cache@v2
- name: "Setup sccache"
uses: mozilla-actions/[email protected]
- name: "Install gcc"
if: matrix.gcc != ''
run: sudo apt update && sudo apt install -yq ${{ matrix.gcc }}
- name: "Setup Rust toolchain"
run: rustup toolchain install nightly --profile default --target ${{ matrix.target }} --no-self-update
- name: "Build"
run: cargo build --release --locked --target ${{ matrix.target }}
- name: "Pack artifact"
shell: powershell
working-directory: ${{ github.workspace }}
# We have to create a zip arch in order for draft to find it as the upload job handles it outside the container or gh handles it directly
run: |
$ARTIFACT_NAME="${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }}"
$DRAFT_DIR="${ARTIFACT_NAME}"
New-Item -ItemType Directory -Path "$ARTIFACT_NAME"
Copy-Item -Path "target\${{ matrix.target }}\release\${{ env.PROJECT_NAME }}.exe" -Destination "$ARTIFACT_NAME"
Copy-Item -Path "README.md", "LICENSE-APACHE", "LICENSE-MIT" -Destination "$ARTIFACT_NAME"
Compress-Archive -Path "$ARTIFACT_NAME\*" -Destination "$ARTIFACT_NAME.zip"
- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }} # Adding .zip to the name will cause XYZ.zip.zip (Where the second one is just a naming convention)
path: ${{ env.PROJECT_NAME }}-${{ matrix.target }}-${{ github.ref_name }}.zip # We don't want the zipped archive as upload-artifact already zips it
if-no-files-found: 'error'
compression-level: '9'
# overwrite: 'true'
draft:
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
runs-on: ubuntu-latest
needs: [build-unix, build-windows]
steps:
- name: "Checkout sources"
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
id: artifact-download-step
with:
merge-multiple: true
- name: "Draft"
uses: softprops/action-gh-release@master
with:
# repository: ${{ github.repository }}
fail_on_unmatched_files: true
draft: true
# make_latest: true ## Drafts & prereleases cannot be set as `make_latest:`
files: |
${{ env.PROJECT_NAME }}-*
generate_release_notes: true
# body_path: ${{ github.workspace }}-CHANGELOG.txt ## For adding changelog content
nightly:
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
permissions:
contents: write
runs-on: ubuntu-latest
needs: [build-unix, build-windows]
steps:
- run: |
echo 'NIGHTLY_BODY<<EOF' >> $GITHUB_ENV
echo "From commit: ${GITHUB_SHA:0:8}" >> $GITHUB_ENV
echo "Generated on: $(date -u +"%Y-%m-%d %H:%M") UTC" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: "Update the tag"
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag --force nightly && git push --force origin tag nightly
- name: "Nightly"
uses: softprops/action-gh-release@v2
with:
tag_name: nightly
prerelease: true
fail_on_unmatched_files: true
files: |
${{ env.PROJECT_NAME }}-*
name: Nightly Build
body: ${{ env.NIGHTLY_BODY }}
target_commitish: ${{ github.sha }}