Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteJanz committed Jun 22, 2024
1 parent dbf2ab7 commit 79c6648
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "." # Location of package manifests
schedule:
interval: "weekly"
69 changes: 69 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Source of this pipeline code: https://github.com/paskausks/rust-bin-github-workflows
# MIT License - Copyright (c) 2019 Rihards Paskausks
# Modified by
# Copyright (c) 2024 Malte Janz

name: CI

on:
pull_request: # trigger on pull requests
push:
branches: # array of glob patterns matching against refs/heads. Optional; defaults to all
- main # triggers on pushes that contain changes in main

jobs:
build:
name: Build

runs-on: ubuntu-latest # full build + test on every major platform is done by the release pipeline

steps:
- uses: actions/checkout@v4

- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Cargo build
run: cargo build --verbose

- name: Cargo test
run: cargo test --verbose --all-features


rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- uses: Swatinem/rust-cache@v2

- name: Run cargo fmt
run: cargo fmt -- --check


clippy_check:
name: Clippy check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- uses: Swatinem/rust-cache@v2

- uses: giraffate/clippy-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --all-features
reporter: 'github-pr-review'
146 changes: 146 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Source of this pipeline code: https://github.com/paskausks/rust-bin-github-workflows
# MIT License - Copyright (c) 2019 Rihards Paskausks
# Modified by
# Copyright (c) 2024 Malte Janz

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create and deploy release

env:
# Could, potentially automatically parse
# the bin name, but let's do it automatically for now.
RELEASE_BIN: sw-sync-cli

# Space separated paths to include in the archive.
# Start relative paths with a dot if you don't want
# paths to be preserved. Use "/" as a delimiter.
RELEASE_ADDS: README.md LICENSE

# Name of the docker image
CONTAINER_IMG_NAME: "maltejanz/sw-sync-cli"


jobs:
tag_version:
name: Get the version from tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}

steps:
- name: Save version from tag
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT


build:
name: Build artifacts
needs: [tag_version]

runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- build: x86_64-unknown-linux-gnu
os: ubuntu-latest
type: application/gzip
output_ending: .tar.gz
- build: x86_64-apple-darwin
os: macos-latest
type: application/gzip
output_ending: .tar.gz
- build: aarch64-apple-darwin
os: macos-14 # m1 runner
type: application/gzip
output_ending: .tar.gz
- build: x86_64-pc-windows-msvc
os: windows-latest
type: application/zip
output_ending: .zip

steps:
- uses: actions/checkout@v4

- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Final cargo test
run: cargo test --verbose --all-features

- name: Run cargo build
run: cargo build --release --verbose

- name: Create artifact directory
run: mkdir artifacts

- name: Create archive for Windows
run: 7z a -tzip ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }} ./target/release/${{ env.RELEASE_BIN }}.exe ${{ env.RELEASE_ADDS }}
if: matrix.os == 'windows-latest'

- name: Create archive for Linux
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -tgzip -si ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }}
if: matrix.os == 'ubuntu-latest'

- name: Install p7zip on MacOS
# 7Zip not available on MacOS, install p7zip via homebrew.
run: brew install p7zip
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'

- name: Create archive for MacOS
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -tgzip -si ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }}
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: executables
path: artifacts/*
if-no-files-found: error


github_draft_release:
name: Create GitHub draft release
needs: [tag_version, build]
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v3
with:
name: executables
path: artifacts

- name: Create draft release
id: create_release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref }}
name: Release ${{ needs.tag_version.outputs.version }}
draft: true
prerelease: false
files: |
artifacts/*
publish_crate:
name: Publish to crates.io
needs: [tag_version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable

- name: Publish sw-sync-cli
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: cargo publish --token ${CRATES_TOKEN}
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name = "sw-sync-cli"
version = "0.1.0"
edition = "2021"
description = "CLI for fast and flexible data transfer between shopware <-> (CSV) file over API"
keywords = ["cli", "shopware", "import", "export"]
categories = ["command-line-utilities", "development-tools", "web-programming"]
authors = ["Malte Janz <[email protected]>"]
license = "MIT"

[dependencies]
clap = { version = "4.5.7", features = ["derive"] }
Expand Down

0 comments on commit 79c6648

Please sign in to comment.