diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..caf0658 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,172 @@ +name: Tests and release +on: [push, pull_request] +env: + CRATE_NAME: hg-git-fast-import + GITHUB_TOKEN: ${{ github.token }} + RUST_BACKTRACE: 1 +jobs: + test: + name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }} + runs-on: ${{ matrix.platform.os }} + strategy: + fail-fast: false + matrix: + platform: + # - os_name: FreeBSD-x86_64 + # os: ubuntu-20.04 + # target: x86_64-unknown-freebsd + # bin: hg-git-fast-import + # name: hg-git-fast-import-FreeBSD-x86_64.tar.gz + # skip_tests: true + - os_name: Linux-x86_64 + os: ubuntu-20.04 + target: x86_64-unknown-linux-musl + bin: hg-git-fast-import + name: hg-git-fast-import-Linux-x86_64-musl.tar.gz + - os_name: Linux-aarch64 + os: ubuntu-20.04 + target: aarch64-unknown-linux-musl + bin: hg-git-fast-import + name: hg-git-fast-import-Linux-aarch64-musl.tar.gz + - os_name: Linux-arm + os: ubuntu-20.04 + target: arm-unknown-linux-musleabi + bin: hg-git-fast-import + name: hg-git-fast-import-Linux-arm-musl.tar.gz + - os_name: Linux-i686 + os: ubuntu-20.04 + target: i686-unknown-linux-musl + bin: hg-git-fast-import + name: hg-git-fast-import-Linux-i686-musl.tar.gz + skip_tests: true + # - os_name: Linux-powerpc + # os: ubuntu-20.04 + # target: powerpc-unknown-linux-gnu + # bin: hg-git-fast-import + # name: hg-git-fast-import-Linux-powerpc-gnu.tar.gz + # skip_tests: true + # - os_name: Linux-powerpc64 + # os: ubuntu-20.04 + # target: powerpc64-unknown-linux-gnu + # bin: hg-git-fast-import + # name: hg-git-fast-import-Linux-powerpc64-gnu.tar.gz + # skip_tests: true + # - os_name: Linux-powerpc64le + # os: ubuntu-20.04 + # target: powerpc64le-unknown-linux-gnu + # bin: hg-git-fast-import + # name: hg-git-fast-import-Linux-powerpc64le.tar.gz + # skip_tests: true + - os_name: Linux-riscv64 + os: ubuntu-20.04 + target: riscv64gc-unknown-linux-gnu + bin: hg-git-fast-import + name: hg-git-fast-import-Linux-riscv64gc-gnu.tar.gz + # - os_name: Linux-s390x + # os: ubuntu-20.04 + # target: s390x-unknown-linux-gnu + # bin: hg-git-fast-import + # name: hg-git-fast-import-Linux-s390x-gnu.tar.gz + # skip_tests: true + # - os_name: NetBSD-x86_64 + # os: ubuntu-20.04 + # target: x86_64-unknown-netbsd + # bin: hg-git-fast-import + # name: hg-git-fast-import-NetBSD-x86_64.tar.gz + # skip_tests: true + - os_name: Windows-aarch64 + os: windows-latest + target: aarch64-pc-windows-msvc + bin: hg-git-fast-import.exe + name: hg-git-fast-import-Windows-aarch64.zip + skip_tests: true + - os_name: Windows-i686 + os: windows-latest + target: i686-pc-windows-msvc + bin: hg-git-fast-import.exe + name: hg-git-fast-import-Windows-i686.zip + skip_tests: true + - os_name: Windows-x86_64 + os: windows-latest + target: x86_64-pc-windows-msvc + bin: hg-git-fast-import.exe + name: hg-git-fast-import-Windows-x86_64.zip + - os_name: macOS-x86_64 + os: macOS-latest + target: x86_64-apple-darwin + bin: hg-git-fast-import + name: hg-git-fast-import-Darwin-x86_64.tar.gz + - os_name: macOS-aarch64 + os: macOS-latest + target: aarch64-apple-darwin + bin: hg-git-fast-import + name: hg-git-fast-import-Darwin-aarch64.tar.gz + skip_tests: true + toolchain: + - stable + # - beta + # - nightly + steps: + - uses: actions/checkout@v4 + - name: Cache cargo & target directories + uses: Swatinem/rust-cache@v2 + with: + key: "v2" + - name: Configure Git + run: | + git config --global user.email "jdoe@example.com" + git config --global user.name "J. Doe" + - name: Install musl-tools on Linux + run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools + if: contains(matrix.platform.name, 'musl') + - name: Build binary + uses: houseabsolute/actions-rust-cross@v0 + with: + command: "build" + target: ${{ matrix.platform.target }} + toolchain: ${{ matrix.toolchain }} + args: "--locked --release" + strip: true + - name: Run tests + uses: houseabsolute/actions-rust-cross@v0 + with: + command: "test" + target: ${{ matrix.platform.target }} + toolchain: ${{ matrix.toolchain }} + args: "--locked --release" + if: ${{ !matrix.platform.skip_tests }} + - name: Package as archive + shell: bash + run: | + cd target/${{ matrix.platform.target }}/release + if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then + 7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + else + tar czvf ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + fi + cd - + if: | + matrix.toolchain == 'stable' && + ( startsWith( github.ref, 'refs/tags/v' ) || + github.ref == 'refs/tags/test-release' ) + - name: Publish release artifacts + uses: actions/upload-artifact@v3 + with: + name: hg-git-fast-import-${{ matrix.platform.os_name }} + path: "hg-git-fast-import-*" + if: matrix.toolchain == 'stable' && github.ref == 'refs/tags/test-release' + - name: Generate SHA-256 + run: shasum -a 256 ${{ matrix.platform.name }} + if: | + matrix.toolchain == 'stable' && + matrix.platform.os == 'macOS-latest' && + ( startsWith( github.ref, 'refs/tags/v' ) || + github.ref == 'refs/tags/test-release' ) + - name: Publish GitHub release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: "hg-git-fast-import*" +# body_path: Changes.md + generate_release_notes: true + if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' ) \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6fc09c9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,129 +0,0 @@ -# Based on the "trust" template v0.1.2 -# https://github.com/japaric/trust/tree/v0.1.2 - -dist: trusty -language: rust -services: docker -sudo: required - -# TODO Rust builds on stable by default, this can be -# overridden on a case by case basis down below. - -env: - global: - - CRATE_NAME=hg-git-fast-import - -matrix: - # TODO These are all the build jobs. Adjust as necessary. Comment out what you - # don't need - include: - # Android - #- env: TARGET=aarch64-linux-android DISABLE_TESTS=1 - #- env: TARGET=arm-linux-androideabi DISABLE_TESTS=1 - #- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1 - #- env: TARGET=i686-linux-android DISABLE_TESTS=1 - #- env: TARGET=x86_64-linux-android DISABLE_TESTS=1 - - # iOS - #- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1 - # os: osx - #- env: TARGET=armv7-apple-ios DISABLE_TESTS=1 - # os: osx - #- env: TARGET=armv7s-apple-ios DISABLE_TESTS=1 - # os: osx - #- env: TARGET=i386-apple-ios DISABLE_TESTS=1 - # os: osx - #- env: TARGET=x86_64-apple-ios DISABLE_TESTS=1 - # os: osx - - # Linux - #- env: TARGET=aarch64-unknown-linux-gnu - #- env: TARGET=arm-unknown-linux-gnueabi - #- env: TARGET=armv7-unknown-linux-gnueabihf - #- env: TARGET=i686-unknown-linux-gnu - - env: TARGET=i686-unknown-linux-musl - #- env: TARGET=mips-unknown-linux-gnu - #- env: TARGET=mips64-unknown-linux-gnuabi64 - #- env: TARGET=mips64el-unknown-linux-gnuabi64 - #- env: TARGET=mipsel-unknown-linux-gnu - #- env: TARGET=powerpc-unknown-linux-gnu - #- env: TARGET=powerpc64-unknown-linux-gnu - #- env: TARGET=powerpc64le-unknown-linux-gnu - #- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1 - #- env: TARGET=x86_64-unknown-linux-gnu - - env: TARGET=x86_64-unknown-linux-musl - - # OSX - #- env: TARGET=i686-apple-darwin - # os: osx - - env: TARGET=x86_64-apple-darwin - os: osx - - # *BSD - #- env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1 - #- env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1 - #- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1 - - # Windows - #- env: TARGET=x86_64-pc-windows-gnu - - # Bare metal - # These targets don't support std and as such are likely not suitable for - # most crates. - # - env: TARGET=thumbv6m-none-eabi - # - env: TARGET=thumbv7em-none-eabi - # - env: TARGET=thumbv7em-none-eabihf - # - env: TARGET=thumbv7m-none-eabi - - # Testing other channels - #- env: TARGET=x86_64-unknown-linux-gnu - # rust: nightly - #- env: TARGET=x86_64-apple-darwin - # os: osx - # rust: nightly - -before_install: - - set -e - - rustup self update - -install: - - sh ci/install.sh - - source ~/.cargo/env || true - -script: - - bash ci/script.sh - -after_script: set +e - -before_deploy: - - sh ci/before_deploy.sh - -deploy: - api_key: - secure: ZknTpCFG5Wut4MBaFB4U3XfMBE2LfLMSP55q3UxlnJEbHumItl9QXxKWA69qSE14xbKufK7/KOjnZfBbQdNTCDjfGcIu5M3sxuJTCHBwU2gMLPmXH2OBY2Rz0fNpimyYaAtIMj7EEcE9bJqbQaS3IQBboHgIHPw+20DmG5zX8lnqY0UaZrpm53KPaPEaRdEEhThTBaP6J3ag+vxc57ry5l5HQxSSZ4PE3ZWUpmwOkulUwiPcd3riIvRskEhweJiRzlqcy3zdBKVHGzqkszGADIYBzDMRtOK/0k/HSe9p1w/C/NZ66vu9zOjL5CJW/+5+3W7znvVBjaotJnait//nwVntDpf6Xujpqb3WvbBN9ZIOl3ErJLIIxoyydV0I958kle/B2NmfV7+dfGeQ/gJT/va2m5Uc0RVp9XHjz4mZpdMXQuNMFqpIZdmZszY3HktUKsfW9Hv7xoSvLk4ZAnr6DaWI042sSL8hKV/9RqA78Tdofd+r74GAlkHct1pa8qN9/R/MBgduzn1Y+8j+lHflpMHnviqPun7ZkozHvNugRx/CLV2aSawRrBHNDwTCBD2D3dWtGqYsA6bq7JEcpxnJwbweCJ2BlV4/j1qkrnIj+Ca8xt/bOvvUWUD3efPh8S9rI3KGkHxHwsrEjEvB/mh8RCy923BzZ+gPICzmXCtnNx8= - file_glob: true - file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* - on: - # TODO Here you can pick which targets will generate binary releases - # In this example, there are some targets that are tested using the stable - # and nightly channels. This condition makes sure there is only one release - # for such targets and that's generated using the stable channel - condition: $TRAVIS_RUST_VERSION = stable - tags: true - provider: releases - skip_cleanup: true - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -branches: - only: - # release tags - - /^v\d+\.\d+\.\d+.*$/ - - master - -notifications: - email: - on_success: never diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..8aaa9cd --- /dev/null +++ b/Cross.toml @@ -0,0 +1,4 @@ +[build.env] +passthrough = [ + "GITHUB_TOKEN", +] diff --git a/Makefile b/Makefile deleted file mode 100644 index 9eafa5a..0000000 --- a/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -profile: - cargo build --release --example private_single_stable - cp callgrind.annotate callgrind.annotate.`date '+%Y%m%d%H%M%S'` || true - valgrind --callgrind-out-file=callgrind.profile --tool=callgrind target/release/examples/private_single_stable - callgrind_annotate --auto=yes --inclusive=yes --tree=both callgrind.profile > callgrind.annotate - less callgrind.annotate \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index bac7dd4..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,91 +0,0 @@ -# Based on the "trust" template v0.1.2 -# https://github.com/japaric/trust/tree/v0.1.2 - -environment: - global: - # TODO This is the Rust channel that build jobs will use by default but can be - # overridden on a case by case basis down below - RUST_VERSION: stable - - # TODO Update this to match the name of your project. - CRATE_NAME: hg-git-fast-import - - # TODO These are all the build jobs. Adjust as necessary. Comment out what you - # don't need - matrix: - # MinGW - #- TARGET: i686-pc-windows-gnu - #- TARGET: x86_64-pc-windows-gnu - - # MSVC - - TARGET: i686-pc-windows-msvc - - TARGET: x86_64-pc-windows-msvc - - # Testing other channels - #- TARGET: x86_64-pc-windows-gnu - # RUST_VERSION: nightly - #- TARGET: x86_64-pc-windows-msvc - # RUST_VERSION: nightly - -install: - - ps: >- - If ($Env:TARGET -eq 'x86_64-pc-windows-gnu') { - $Env:PATH += ';C:\msys64\mingw64\bin' - } ElseIf ($Env:TARGET -eq 'i686-pc-windows-gnu') { - $Env:PATH += ';C:\msys64\mingw32\bin' - } - - curl -sSf -o rustup-init.exe https://win.rustup.rs/ - - rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_VERSION% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -Vv - - cargo -V - -# TODO This is the "test phase", tweak it as you see fit -test_script: - # we don't run the "test phase" when doing deploys - - if [%APPVEYOR_REPO_TAG%]==[false] ( - cargo build --target %TARGET% && - cargo build --target %TARGET% --release && - cargo test --target %TARGET% && - cargo test --target %TARGET% --release - ) - -before_deploy: - # TODO Update this to build the artifacts that matter to you - - cargo rustc --target %TARGET% --release --bin hg-git-fast-import -- -C lto - - ps: ci\before_deploy.ps1 - -deploy: - artifact: /.*\.zip/ - # TODO update `auth_token.secure` - # - Create a `public_repo` GitHub token. Go to: https://github.com/settings/tokens/new - # - Encrypt it. Go to https://ci.appveyor.com/tools/encrypt - # - Paste the output down here - auth_token: - secure: ERWky5aS7gNXh7E9dx1tdPl0oZjWfJE22uWZ9weACgqQPsu2W2xl1CcMTfGRMfcm - description: '' - on: - # TODO Here you can pick which targets will generate binary releases - # In this example, there are some targets that are tested using the stable - # and nightly channels. This condition makes sure there is only one release - # for such targets and that's generated using the stable channel - RUST_VERSION: stable - appveyor_repo_tag: true - provider: GitHub - -cache: - - C:\Users\appveyor\.cargo\registry - - target - -branches: - only: - # Release tags - - /^v\d+\.\d+\.\d+.*$/ - - master - -notifications: - - provider: Email - on_build_success: false - -# Building is done in the test phase, so we disable Appveyor's build phase. -build: false diff --git a/build-pgo-generate.sh b/build-pgo-generate.sh deleted file mode 100755 index 9a00646..0000000 --- a/build-pgo-generate.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -rm -rf /tmp/pgo-data - -# STEP 1: Build the instrumented binaries -RUSTFLAGS="-Cprofile-generate=/tmp/pgo-data" \ - cargo build --release diff --git a/build-pgo-use.sh b/build-pgo-use.sh deleted file mode 100755 index 0278b6f..0000000 --- a/build-pgo-use.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -PATH=$PATH:~/.rustup/toolchains/`rustup show active-toolchain | cut -f1 -d" "`/lib/rustlib/x86_64-apple-darwin/bin/ - -# STEP 3: Merge the `.profraw` files into a `.profdata` file -llvm-profdata merge -o /tmp/pgo-data/merged.profdata /tmp/pgo-data - -# STEP 4: Use the `.profdata` file for guiding optimizations -RUSTFLAGS="-Cprofile-use=/tmp/pgo-data/merged.profdata" \ - cargo build --release \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7909a32 --- /dev/null +++ b/build.rs @@ -0,0 +1,13 @@ +use std::env; + +// mostly copied from the current_platform crate. +fn main() { + // Cargo sets the host and target env vars for build scripts, but not + // crates: + // https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts + // So we just re-export them to the crate code. + println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); + // By default Cargo only runs the build script when a file changes. This + // makes it re-run on target change + println!("cargo:rerun-if-changed-env=TARGET"); +} diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 deleted file mode 100644 index cc1061d..0000000 --- a/ci/before_deploy.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -# This script takes care of packaging the build artifacts that will go in the -# release zipfile - -$SRC_DIR = $PWD.Path -$STAGE = [System.Guid]::NewGuid().ToString() - -Set-Location $ENV:Temp -New-Item -Type Directory -Name $STAGE -Set-Location $STAGE - -$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" - -# TODO Update this to package the right artifacts -Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\hg-git-fast-import.exe" '.\' - -7z a "$ZIP" * - -Push-AppveyorArtifact "$ZIP" - -Remove-Item *.* -Force -Set-Location .. -Remove-Item $STAGE -Set-Location $SRC_DIR diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh deleted file mode 100644 index 9a4b7d2..0000000 --- a/ci/before_deploy.sh +++ /dev/null @@ -1,33 +0,0 @@ -# This script takes care of building your crate and packaging it for release - -set -ex - -main() { - local src=$(pwd) \ - stage= - - case $TRAVIS_OS_NAME in - linux) - stage=$(mktemp -d) - ;; - osx) - stage=$(mktemp -d -t tmp) - ;; - esac - - test -f Cargo.lock || cargo generate-lockfile - - # TODO Update this to build the artifacts that matter to you - cross rustc --bin hg-git-fast-import --target $TARGET --release -- -C lto - - # TODO Update this to package the right artifacts - cp target/$TARGET/release/hg-git-fast-import $stage/ - - cd $stage - tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * - cd $src - - rm -rf $stage -} - -main diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index 80e18e4..0000000 --- a/ci/install.sh +++ /dev/null @@ -1,47 +0,0 @@ -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - case $TARGET in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index e5db2cd..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,24 +0,0 @@ -# This script takes care of testing your crate - -set -ex - -# TODO This is the "test phase", tweak it as you see fit -main() { - cross build --target $TARGET - cross build --target $TARGET --release - - if [ ! -z $DISABLE_TESTS ]; then - return - fi - - cross test --target $TARGET - cross test --target $TARGET --release - - #cross run --target $TARGET - #cross run --target $TARGET --release -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi diff --git a/src/git.rs b/src/git.rs index c88a233..c0e222d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,16 +1,16 @@ -use super::read_file; -use super::{ - config::RepositorySavedState, env::Environment, TargetRepository, TargetRepositoryError, +use std::{ + collections::HashSet, + fs::{self, File}, + io::prelude::Write, + path::{Path, PathBuf}, + process::{Child, Command, ExitStatus, Stdio}, }; -use std::collections::HashSet; -use std::path::Path; -use std::path::PathBuf; +use super::{ + config::RepositorySavedState, env::Environment, read_file, TargetRepository, + TargetRepositoryError, +}; -use std::fs; -use std::fs::File; -use std::io::prelude::*; -use std::process::{Child, Command, ExitStatus, Stdio}; use tracing::{debug, error, info}; pub const DEFAULT_BRANCH: &str = "master"; diff --git a/templates/README.md b/templates/README.md index c3d98c3..ed29bff 100644 --- a/templates/README.md +++ b/templates/README.md @@ -1,7 +1,5 @@ # Mercurial to Git converter using git fast-import with multi repository import support -[![Linux build status](https://travis-ci.org/kilork/hg-git-fast-import.svg)](https://travis-ci.org/kilork/hg-git-fast-import) -[![Windows build status](https://ci.appveyor.com/api/projects/status/github/kilork/hg-git-fast-import?svg=true)](https://ci.appveyor.com/project/kilork/hg-git-fast-import) [![Crates.io](https://img.shields.io/crates/v/hg-git-fast-import.svg)](https://crates.io/crates/hg-git-fast-import) [![Packaging status](https://repology.org/badge/tiny-repos/hg-git-fast-import.svg)](https://repology.org/project/hg-git-fast-import/badges) [![hg-git-fast-import](https://snapcraft.io//hg-git-fast-import/badge.svg)](https://snapcraft.io/hg-git-fast-import)