Skip to content

Commit

Permalink
Merge pull request #96 from Lordfirespeed/actions-housekeeping
Browse files Browse the repository at this point in the history
Actions/Workflows housekeeping
  • Loading branch information
MythicManiac committed Dec 6, 2023
2 parents 9de949b + c18cd03 commit adf0290
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ charset = utf-8
indent_style = space
indent_size = 4

[*.yml]
indent_size = 2

[*.{cs,vb}]
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules
csharp_new_line_before_open_brace = all
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ on:

jobs:
nuget:
name: Publish NuGet Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'

- name: Fetch Latest .nupkg
uses: dsaltares/fetch-gh-release-asset@0efe227dedb360b09ea0e533795d584b61c461a9
uses: dsaltares/fetch-gh-release-asset@1.1.1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
version: "tags/${{ github.ref_name }}"
file: "tcli.${{ github.ref_name }}.nupkg"
target: "tcli.nupkg"


- name: Publish to NuGet
shell: bash
run: dotnet nuget push tcli.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
58 changes: 38 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ on:
jobs:
# Validate tag with proper regex since the check above is very limited.
validate-tag:
name: Validate tag semantic version
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@v2
- id: tag
uses: dawidd6/action-get-tag@v1
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: Ensure triggering ref is a tag
id: tag
uses: devops-actions/action-get-tag@v1.0.2

- id: regex-match
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ steps.tag.outputs.tag }}
regex: '^([1-9][0-9]*|[0-9])\.([1-9][0-9]*|[0-9])\.([1-9][0-9]*|[0-9])$'
regex: '^([1-9][0-9]*|0)\.([1-9][0-9]*|0)\.([1-9][0-9]*|0)$'

- id: fail-fast
if: ${{ steps.regex-match.outputs.match == '' }}
uses: actions/github-script@v3
uses: actions/github-script@v7
with:
script: core.setFailed('Tag is invalid')

platform-binary:
name: Build binaries for ${{ matrix.target }}
needs: validate-tag
if: github.event.base_ref == 'refs/heads/master'
name: Create binary ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -43,19 +51,24 @@ jobs:
target: osx-x64
os: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'
- id: tag
uses: dawidd6/action-get-tag@v1

- name: Install dependencies
run: dotnet restore

- name: Setup Cargo/Rust
uses: moonrepo/setup-rust@v1

- name: Build
shell: bash
run: |
release_name="tcli-${{ steps.tag.outputs.tag }}-${{ matrix.target }}"
release_name="tcli-${{ needs.validate-tag.outputs.tag }}-${{ matrix.target }}"
dotnet publish ThunderstoreCLI/ThunderstoreCLI.csproj -c Release -r "${{ matrix.target }}" --self-contained true -f net7.0 -o "${release_name}"
if [ "${{ matrix.target }}" == "win-x64" ]; then
Expand All @@ -66,39 +79,44 @@ jobs:
rm -r ${release_name}
- name: Publish to GitHub
- name: Add build artifacts to draft GitHub release
uses: softprops/action-gh-release@v1
with:
files: "tcli*"
name: "Thunderstore CLI ${{ steps.tag.outputs.tag }}"
name: "Thunderstore CLI ${{ needs.validate-tag.outputs.tag }}"
body_path: ${{ github.workspace }}/.github/RELEASE_TEMPLATE.md
draft: true
prerelease: ${{ startsWith(steps.tag.outputs.tag, '0.') }}

nupkg:
name: Build NuGet Package
needs: validate-tag
if: github.event.base_ref == 'refs/heads/master'
name: Create .nupkg
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'
- id: tag
uses: dawidd6/action-get-tag@v1

- name: Install dependencies
run: dotnet restore

- name: Setup Cargo/Rust
uses: moonrepo/setup-rust@v1

- name: Build
shell: bash
run: dotnet pack ThunderstoreCLI/ThunderstoreCLI.csproj -c Release -o "." -p:EnableInstallers=false -p:PublishSelfContained=false -p:PublishSingleFile=false -p:PublishTrimmed=false -p:PublishReadyToRun=false

- name: Publish to GitHub
- name: Add build artifacts to draft GitHub release
uses: softprops/action-gh-release@v1
with:
files: "tcli*"
name: "Thunderstore CLI ${{ steps.tag.outputs.tag }}"
name: "Thunderstore CLI ${{ needs.validate-tag.outputs.tag }}"
body_path: ${{ github.workspace }}/.github/RELEASE_TEMPLATE.md
draft: true
prerelease: ${{ startsWith(steps.tag.outputs.tag, '0.') }}
40 changes: 32 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
name: Build & Test

on: [push]
on:
# Trigger on pushes to the main branch
push:
branches: [ master ]
# Trigger on any pull request
pull_request:

jobs:
pre-commit:
name: Code style check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'
- uses: actions/setup-python@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install pre-commit

- name: Install pre-commit framework
run: curl https://pre-commit.com/install-local.py | python -

- name: Install dotnet-format
run: dotnet tool install -g dotnet-format

- name: Run pre-commit
run: ~/bin/pre-commit run --show-diff-on-failure --color=always --all-files

Expand All @@ -30,19 +43,30 @@ jobs:
env:
OS: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- name: Checkout ref that triggered workflow
uses: actions/checkout@v4

- name: setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'

- name: Setup Cargo/Rust
uses: moonrepo/setup-rust@v1

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Run xUnit tests
run: dotnet test -p:EnableInstallers=false --collect:"XPlat Code Coverage"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
directory: ./ThunderstoreCLI.Tests/TestResults/
env_vars: OS
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# thunderstore-cli

[![Build & Test](https://github.com/thunderstore-io/thunderstore-cli/actions/workflows/test.yml/badge.svg)](https://github.com/thunderstore-io/thunderstore-cli/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/thunderstore-io/thunderstore-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/thunderstore-io/thunderstore-cli)
[![NuGet Package](https://img.shields.io/nuget/v/tcli)](https://www.nuget.org/packages/tcli)
[![downloads](https://img.shields.io/nuget/dt/tcli)](https://www.nuget.org/packages/tcli)

Thunderstore CLI (just "TCLI" from here on) is a command line tool for building and uploading mod packages to
[Thunderstore](https://thunderstore.io/) mod database, and installing mods via the command line.
Expand Down

0 comments on commit adf0290

Please sign in to comment.