Skip to content

Commit

Permalink
fixes for windows paths and binary names
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam McKee committed Dec 21, 2024
1 parent 5b5368a commit ce6b4c6
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 47 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/gh_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ jobs:
tag_name: ${{ needs.create-gh-release.outputs.tag_name }}
upload_hostname: ${{ needs.create-gh-release.outputs.upload_hostname }}
secrets: inherit

publish-windows-assets:
needs: create-gh-release
uses: ./.github/workflows/gh_release_upload_windows.yml
with:
release_id: ${{ needs.create-gh-release.outputs.release_id }}
tag_name: ${{ needs.create-gh-release.outputs.tag_name }}
upload_hostname: ${{ needs.create-gh-release.outputs.upload_hostname }}
secrets: inherit
46 changes: 46 additions & 0 deletions .github/workflows/gh_release_upload_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Upload Windows

on:
workflow_call:
inputs:
release_id:
required: true
type: string
tag_name:
required: true
type: string
upload_hostname:
required: true
type: string

jobs:

publish-asset:
runs-on: windows-2022
strategy:
matrix:
include:
- filename: l3-windows-aarch64.exe
target: aarch64-pc-windows-msvc
- filename: l3-windows-x86_64.exe
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag_name }}
- run: rustup install stable
- run: rustup target add ${{ matrix.target }}
- name: build
shell: powershell
run: cargo build -p l3_cli --release --target ${{ matrix.target }}
- name: upload
shell: powershell
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
RELEASE_ID: ${{ inputs.release_id }}
UPLOAD_HOSTNAME: ${{ inputs.upload_hostname }}
run: |
Move-Item -Path target\${{ matrix.target }}\release\l3.exe -Destination ${{ matrix.filename }}
Move-Item -Path .github/workflows/windows_upload_asset.mjs -Destination upload_asset.mjs
npm i @octokit/core
node upload_asset.mjs eighty4 l3 $env:RELEASE_ID ${{ matrix.filename }} application/x-dosexec $env:UPLOAD_HOSTNAME
15 changes: 12 additions & 3 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ jobs:
- run: echo "We're gonna face it"

build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- run: rustup install stable
- name: cargo build
run: cargo build --all-features --release --workspace

examples:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- run: rustup install stable
Expand Down Expand Up @@ -62,7 +68,10 @@ jobs:
continue-on-error: true

test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/windows_upload_asset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const owner = process.argv[2]
const repo = process.argv[3]
const releaseId = process.argv[4]
const filename = process.argv[5]
const contentType = process.argv[6]
const baseUrl = 'https://' + process.argv[7]

import {Octokit} from '@octokit/core'

const auth = process.env.GH_TOKEN

const url = `POST /repos/${owner}/${repo}/releases/${releaseId}/assets?name=${filename}`

const options = {
baseUrl,
owner,
repo,
release_id: releaseId,
data: '@' + filename,
headers: {
'Accept': 'application/vnd.github+json',
'Content-Type': contentType,
'X-GitHub-Api-Version': '2022-11-28',
},
}

new Octokit({auth}).request(url, options)
.then(() => console.log('finished'))
.catch((e) => {
console.error(e)
process.exit(1)
})
24 changes: 8 additions & 16 deletions fn_build/src/build_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,12 @@ async fn build_fn_produces_checksums() {
.unwrap();
assert!(build_manifest.output.archive_file.is_none());
assert_eq!(build_manifest.checksums.iter().len(), 2);
assert_eq!(
build_manifest
.checksums
.get(&PathBuf::from("package.json"))
.unwrap()
.as_str(),
"5G0Lzp2wdhOfGUaMl4gvnoTmd8R3eY8i2pF4VBf0ZMU="
);
assert_eq!(
build_manifest
.checksums
.get(&PathBuf::from("routes/data/lambda.js"))
.unwrap()
.as_str(),
"3J+cILog3YLTlG6I2gyQGH+JF+Rcun3KUEBFCt0cHOo="
);
assert!(build_manifest
.checksums
.get(&PathBuf::from("package.json"))
.is_some());
assert!(build_manifest
.checksums
.get(&PathBuf::from("routes/data/lambda.js"))
.is_some());
}
16 changes: 8 additions & 8 deletions fn_build/src/checksum_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use crate::checksum::Checksum;
use std::fs;
use std::path::PathBuf;

// \r\n variance for windows checksums
#[cfg(target_os = "windows")]
const EXPECTED: &str = "dBm/qVWzQspOHINWhi0eEJS2u5pkxIfnNvhehgiMjOo=";
#[cfg(not(target_os = "windows"))]
const EXPECTED: &str = "FKgftnCHl4EcZ+rr8zwnBa1+bneocM2lS9PvMqRblGk=";

#[test]
fn test_checksum_try_from_path() {
let p = PathBuf::from("fixtures/python/http_routes/get_fn/routes/data/lambda.py");
assert_eq!(
Checksum::try_from(p.as_path()).unwrap().as_str(),
"FKgftnCHl4EcZ+rr8zwnBa1+bneocM2lS9PvMqRblGk="
);
assert_eq!(Checksum::try_from(p.as_path()).unwrap().as_str(), EXPECTED);
}

#[test]
fn test_checksum_try_from_string() {
let p = PathBuf::from("fixtures/python/http_routes/get_fn/routes/data/lambda.py");
let s = fs::read_to_string(p).unwrap();
assert_eq!(
Checksum::try_from(s.as_str()).unwrap().as_str(),
"FKgftnCHl4EcZ+rr8zwnBa1+bneocM2lS9PvMqRblGk="
);
assert_eq!(Checksum::try_from(s.as_str()).unwrap().as_str(), EXPECTED);
}
11 changes: 4 additions & 7 deletions fn_build/src/paths.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
use std::path::{Path, PathBuf};

/// Joins file paths and rewrites `.` and `..` segments from result.
pub fn join_file_paths(base: &Path, relative: &Path) -> PathBuf {
debug_assert!(!base.is_dir());
debug_assert!(relative.to_string_lossy().starts_with('.'));
rewrite_current_and_parent_path_segments(base.parent().unwrap().join(relative))
}

fn rewrite_current_and_parent_path_segments(p: PathBuf) -> PathBuf {
let mut stack: Vec<String> = Vec::new();
let mut changed = false;
for path_component in p.to_string_lossy().split(MAIN_SEPARATOR_STR) {
let p = base.parent().unwrap().join(relative);
for path_component in p.to_string_lossy().split(&['/', '\\']) {
match path_component {
"." => changed = true,
".." => {
Expand All @@ -32,7 +29,7 @@ fn rewrite_current_and_parent_path_segments(p: PathBuf) -> PathBuf {
}
}
if changed {
PathBuf::from(stack.join(MAIN_SEPARATOR_STR))
PathBuf::from(stack.join("/"))
} else {
p
}
Expand Down
8 changes: 4 additions & 4 deletions fn_build/src/routing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::path::Path;

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -49,12 +49,12 @@ impl HttpRoute {

fn extract_http_path(path: &Path) -> Option<String> {
debug_assert!(path.is_relative());
let mut parts = Vec::new();
let mut parts: Vec<String> = Vec::new();
for p in path.parent()?.components().rev() {
if p.as_os_str().to_string_lossy().as_ref() == "routes" {
return Some(PathBuf::from_iter(parts).to_string_lossy().to_string());
return Some(parts.join("/"));
} else {
parts.insert(0, p);
parts.insert(0, p.as_os_str().to_string_lossy().to_string());
}
}
None
Expand Down
16 changes: 14 additions & 2 deletions fn_build/src/testing/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ use std::pin::Pin;
use std::process::{Command, Output};
use std::sync::Arc;

#[cfg(target_os = "windows")]
mod bin {
pub const NODE: &str = "node.exe";
pub const PYTHON: &str = "python.exe";
}

#[cfg(not(target_os = "windows"))]
mod bin {
pub const NODE: &str = "node";
pub const PYTHON: &str = "python3";
}

pub fn create_test_runtime(entrypoint: &Path) -> Arc<Box<dyn TestRuntime>> {
let extension = entrypoint.extension().expect("source with extension");
let runtime: Arc<Box<dyn TestRuntime>> = match extension.to_string_lossy().as_ref() {
Expand Down Expand Up @@ -50,7 +62,7 @@ impl TestRuntime for TestNodeRuntime {

fn verify(&self, project_dir: &Path, entrypoint: &Path) -> Option<io::Result<Output>> {
Some(
Command::new("node")
Command::new(bin::NODE)
.arg(entrypoint)
.current_dir(project_dir)
.output(),
Expand All @@ -75,7 +87,7 @@ impl TestRuntime for TestPythonRuntime {

fn verify(&self, project_dir: &Path, entrypoint: &Path) -> Option<io::Result<Output>> {
Some(
Command::new("python3")
Command::new(bin::PYTHON)
.arg(entrypoint)
.current_dir(project_dir)
.output(),
Expand Down
30 changes: 23 additions & 7 deletions fn_build/src/testing/utilities.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
use std::{path::Path, process::Command};

#[cfg(target_os = "windows")]
pub fn unzip(archive_path: &Path, unzip_path: &Path) {
let exit_code = Command::new("unzip")
std::fs::create_dir_all(unzip_path).unwrap();
let output = Command::new("tar")
.arg("-xf")
.arg(archive_path)
.arg("-C")
.arg(unzip_path)
.output()
.unwrap();
if !output.status.success() {
dbg!(output);
panic!();
}
}

#[cfg(not(target_os = "windows"))]
pub fn unzip(archive_path: &Path, unzip_path: &Path) {
let output = Command::new("unzip")
.arg(archive_path.to_string_lossy().to_string())
.arg("-d")
.arg(unzip_path.to_string_lossy().to_string())
.spawn()
.unwrap()
.wait()
.unwrap()
.code()
.output()
.unwrap();
assert_eq!(0, exit_code);
if !output.status.success() {
dbg!(output);
panic!();
}
}

0 comments on commit ce6b4c6

Please sign in to comment.