Skip to content

Commit

Permalink
Merge pull request #6 from BrosSquad/rewrite/v3-rust
Browse files Browse the repository at this point in the history
Rewrite/v3 rust
  • Loading branch information
CodeLieutenant committed Sep 11, 2022
2 parents 591b6a1 + 44030da commit af451dc
Show file tree
Hide file tree
Showing 45 changed files with 2,265 additions and 1,319 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
hoster/tests/data/utf16-hosts-with-bom-bytes eol=crlf
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,53 @@
name: 'Build'

on:
workflow_dispatch:
workflow_call:
inputs:
profile:
description: 'Cargo build profile (debug|release|dist)'
required: true
type: string
default: dist
env:
RUST_BACKTRACE: 1

jobs:
build:
strategy:
matrix:
rust:
- stable
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.rust }} on ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Test
uses: actions-rs/cargo@v1
id: build
with:
command: build
args: --profile ${{ inputs.profile }} --all
- name: Archive production artifacts
if: ${{ matrix.os != 'windows-latest' }}
uses: actions/upload-artifact@v3
with:
name: hosts-edit-binary-${{ matrix.os }}
path: ./target/${{ inputs.profile }}/hosts-edit
- name: Archive production artifacts
if: ${{ matrix.os == 'windows-latest' }}
uses: actions/upload-artifact@v3
with:
name: hosts-edit-binary-${{ matrix.os }}
path: ./target/${{ inputs.profile }}/hosts-edit.exe
91 changes: 25 additions & 66 deletions .github/workflows/release.yml
Expand Up @@ -5,7 +5,7 @@ on:
tags:
- 'v*'
jobs:
release:
create_release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
Expand All @@ -22,84 +22,43 @@ jobs:
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
unix:
build:
uses: BrosSquad/hosts/.github/workflows/build.yml@master
with:
profile: dist
release:
needs: [create_release, build]
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: [1.16.x]
runs-on: ${{ matrix.os }}
needs: release
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: olegtarasov/get-tag@v2.1
id: git_tag
- name: Download 'Hosts-Edit' binary
uses: actions/download-artifact@v3
with:
tagRegex: 'v(.*)'
tagRegexGroup: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test RACE=1 ENVIRONMENT=production
- name: Build
run: make build VERSION=${{ steps.git_tag.outputs.tag }} RACE=0 ENVIRONMENT=production
env:
CGO_ENABLED: 0
name: hosts-edit-binary-${{ matrix.os }}
- name: Upload Release Asset
id: upload-release-asset
id: upload-release-asset-windows
if: ${{ matrix.os == 'windows-latest' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./bin/hosts
asset_name: hosts-${{ matrix.os }}-${{ steps.git_tag.outputs.tag }}
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./hosts-edit.exe
asset_name: hosts-edit-${{ matrix.os }}.exe
asset_content_type: application/octet-stream
windows:
strategy:
matrix:
go: [1.16.x]
runs-on: windows-latest
needs: release
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: olegtarasov/get-tag@v2.1
id: git_tag
with:
tagRegex: 'v(.*)'
tagRegexGroup: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test RACE=1 ENVIRONMENT=production
- name: Build
run: make build VERSION=${{ steps.git_tag.outputs.tag }} RACE=0 ENVIRONMENT=production EXT=.exe
env:
CGO_ENABLED: 0
- name: Upload Release Asset
id: upload-release-asset
id: upload-release-asset-unix
if: ${{ matrix.os != 'windows-latest' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./bin/hosts.exe
asset_name: hosts-windows-${{ steps.git_tag.outputs.tag }}.exe
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./hosts-edit
asset_name: hosts-edit-${{ matrix.os }}
asset_content_type: application/octet-stream
86 changes: 72 additions & 14 deletions .github/workflows/test.yml
Expand Up @@ -8,25 +8,83 @@ on:
branches:
- master
- dev

env:
RUST_BACKTRACE: 1

jobs:
test:
style:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.15.x, 1.16.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
go-version: 1.16.x
- uses: actions/cache@v2
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: cargo fmt --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
test:
strategy:
matrix:
rust:
- stable
os:
- ubuntu-latest
- windows-latest
- macos-latest
include:
- rust: stable
runs-on: ${{ matrix.os }}
name: Test ${{ matrix.rust }} on ${{ matrix.os }}
needs: [style]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test ${{ matrix.go }}
run: make test RACE=1 ENVIRONMENT=development
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

- name: Test
uses: actions-rs/cargo@v1
with:
command: test

- name: Test all benches
if: matrix.benches
uses: actions-rs/cargo@v1
with:
command: test
args: --benches
miri:
name: Test with Miri
needs: [style]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: miri
override: true

- name: Test
run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test
4 changes: 1 addition & 3 deletions .gitignore
@@ -1,4 +1,2 @@
/target
.idea/
.vscode/
bin/
coverage.txt
4 changes: 4 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,4 @@
{
"version": "0.2.0",
"configurations": []
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,2 @@
{
}
48 changes: 48 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,48 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "clippy",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo clippy"
},
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"args": [
"--release"
],
"group": "build",
"label": "rust: cargo build release"
},
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo build"
},
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"args": [
"--profile",
"dist"
],
"group": "build",
"label": "rust: cargo build dist"
}
]
}

0 comments on commit af451dc

Please sign in to comment.