Merge pull request #116 from fredmorcos/0.10.1-pr #171
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Build+Test+Publish | |
on: | |
push: | |
branches: [main] | |
tags: '*' | |
pull_request: | |
branches: [main] | |
env: | |
CARGO_TERM_COLOR: always | |
RUSTFLAGS: -Dwarnings | |
jobs: | |
setup-build-matrix: | |
name: Setup build matrix | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{steps.set-matrix.outputs.matrix}} | |
steps: | |
- id: set-matrix | |
name: Generate build matrix | |
shell: python | |
# env: | |
# ENABLE_PRODUCTION: ${{startsWith(github.ref, 'refs/tags/')}} | |
run: | | |
import json | |
import os | |
matrix = { | |
'os': [ | |
{ | |
'name': 'linux', | |
'edition': 'ubuntu-22.04', | |
'execext': '', | |
'pkgext': '.tar.bz2', | |
'pkgcmd': ('tar -c -f ' | |
'$PKG.tar.bz2 ' | |
'$PKG'), | |
}, | |
{ | |
'name': 'windows', | |
'edition': 'windows-2022', | |
'execext': '.exe', | |
'pkgext': '.zip', | |
'pkgcmd': ('7z a ' | |
'$PKG.zip ' | |
'$PKG'), | |
}, | |
{ | |
'name': 'macos', | |
'edition': 'macos-14', | |
'execext': '', | |
'pkgext': '.dmg', | |
'pkgcmd': ('hdiutil create -format UDZO -srcfolder ' | |
'$PKG ' | |
'$PKG.dmg'), | |
}, | |
], | |
'build-config': [ | |
{ | |
'id': 'debug', | |
'args': '', | |
}, | |
{ | |
'id': 'release', | |
'args': '--release', | |
}, | |
] | |
} | |
matrix_json = json.dumps(matrix) | |
env_file = os.getenv('GITHUB_OUTPUT') | |
if env_file is not None: | |
with open(env_file, 'a', encoding='utf8') as out: | |
print(f'matrix={matrix_json}', file=out) | |
code-formatting: | |
name: Code formatting | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
components: rustfmt | |
- name: Code formatting | |
uses: actions-rs/cargo@v1 | |
with: | |
command: fmt | |
args: >- | |
--all -- --check -l | |
lint: | |
name: >- | |
Lint: | |
${{matrix.os.edition}}, | |
${{matrix.build-config.id}} | |
needs: setup-build-matrix | |
strategy: | |
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}} | |
runs-on: ${{matrix.os.edition}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
target | |
~/.cargo | |
~/.rustup | |
key: >- | |
lint-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}} | |
restore-keys: | | |
lint-deps-${{matrix.os.name}}-${{matrix.build-config.id}}- | |
lint-deps-${{matrix.os.name}}- | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
components: clippy | |
- name: Lint | |
uses: actions-rs/cargo@v1 | |
with: | |
command: clippy | |
args: >- | |
--all-targets --all-features | |
${{matrix.build-config.args}} | |
documentation: | |
name: >- | |
Doc: | |
${{matrix.os.edition}}, | |
${{matrix.build-config.id}} | |
needs: setup-build-matrix | |
strategy: | |
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}} | |
runs-on: ${{matrix.os.edition}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
target | |
~/.cargo | |
~/.rustup | |
key: >- | |
doc-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}} | |
restore-keys: | | |
doc-deps-${{matrix.os.name}}-${{matrix.build-config.id}}- | |
doc-deps-${{matrix.os.name}}- | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Doc | |
uses: actions-rs/cargo@v1 | |
env: | |
RUSTDOCFLAGS: -Dwarnings | |
with: | |
command: doc | |
args: >- | |
--all-features --no-deps --document-private-items | |
${{matrix.build-config.args}} | |
build-and-test: | |
name: >- | |
Build+Test: | |
${{matrix.os.edition}}, | |
${{matrix.build-config.id}} | |
needs: setup-build-matrix | |
strategy: | |
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}} | |
runs-on: ${{matrix.os.edition}} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dawidd6/action-get-tag@v1 | |
if: ${{startsWith(github.ref, 'refs/tags/')}} | |
id: tag | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
target | |
~/.cargo | |
~/.rustup | |
key: >- | |
build-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}} | |
restore-keys: | | |
build-deps-${{matrix.os.name}}-${{matrix.build-config.id}}- | |
build-deps-${{matrix.os.name}}- | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: >- | |
--all-features --all-targets | |
${{matrix.build-config.args}} | |
- name: Test | |
uses: actions-rs/cargo@v1 | |
with: | |
command: test | |
args: >- | |
--all-features --all-targets | |
${{matrix.build-config.args}} | |
- name: Create tarball | |
if: >- | |
${{matrix.build-config.id == 'release' && | |
startsWith(github.ref, 'refs/tags/')}} | |
shell: bash | |
run: | | |
export PKG=tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}} | |
mkdir $PKG | |
cp target/release/tvrank $PKG/tvrank${{matrix.os.execext}} | |
cp LICENSE $PKG/LICENSE | |
cp README.md $PKG/README.md | |
cp -r changelogs $PKG/changelogs | |
${{matrix.os.pkgcmd}} | |
- name: Upload tarball | |
if: >- | |
${{matrix.build-config.id == 'release' && | |
startsWith(github.ref, 'refs/tags/')}} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: >- | |
tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}}${{matrix.os.pkgext}} | |
path: >- | |
tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}}${{matrix.os.pkgext}} | |
publish-github: | |
name: Publish to Github | |
needs: | |
- code-formatting | |
- lint | |
- documentation | |
- build-and-test | |
if: ${{startsWith(github.ref, 'refs/tags/')}} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dawidd6/action-get-tag@v1 | |
id: tag | |
- name: Download Linux tarball | |
uses: actions/download-artifact@v4 | |
with: | |
name: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2 | |
- name: Download MacOS tarball | |
uses: actions/download-artifact@v4 | |
with: | |
name: tvrank-${{steps.tag.outputs.tag}}-macos.dmg | |
- name: Download Windows tarball | |
uses: actions/download-artifact@v4 | |
with: | |
name: tvrank-${{steps.tag.outputs.tag}}-windows.zip | |
- name: Create Release on Github | |
id: create-release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
with: | |
tag_name: ${{steps.tag.outputs.tag}} | |
release_name: tvrank-${{steps.tag.outputs.tag}} | |
body_path: changelogs/${{steps.tag.outputs.tag}}.md | |
- name: Upload Linux tarball | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
with: | |
upload_url: ${{steps.create-release.outputs.upload_url}} | |
asset_path: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2 | |
asset_name: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2 | |
asset_content_type: application/x-bzip2 | |
- name: Upload MacOS tarball | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
with: | |
upload_url: ${{steps.create-release.outputs.upload_url}} | |
asset_path: tvrank-${{steps.tag.outputs.tag}}-macos.dmg | |
asset_name: tvrank-${{steps.tag.outputs.tag}}-macos.dmg | |
asset_content_type: application/x-apple-diskimage | |
- name: Upload Windows tarball | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
with: | |
upload_url: ${{steps.create-release.outputs.upload_url}} | |
asset_path: tvrank-${{steps.tag.outputs.tag}}-windows.zip | |
asset_name: tvrank-${{steps.tag.outputs.tag}}-windows.zip | |
asset_content_type: application/zip | |
publish-crates-io: | |
name: Publish to Crates.io | |
needs: | |
- code-formatting | |
- lint | |
- documentation | |
- build-and-test | |
if: ${{startsWith(github.ref, 'refs/tags/')}} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Publish to Crates.io | |
env: | |
CRATES_IO_TOKEN: ${{secrets.CRATES_IO_TOKEN}} | |
run: | | |
cargo publish -p tvrank --token ${CRATES_IO_TOKEN} | |
sleep 5 # Gives crates.io time to update itself or whatever | |
cargo publish -p tvrank-cli --token ${CRATES_IO_TOKEN} | |
... |