|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - v* |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + qa: |
| 14 | + name: QA |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - name: Setup Rust |
| 19 | + uses: hecrj/setup-rust-action@v2 |
| 20 | + with: |
| 21 | + rust-version: stable |
| 22 | + profile: minimal |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.12" |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + pip install --upgrade pip |
| 30 | + pip install pre-commit |
| 31 | + - name: Cache dependencies |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/.cargo/registry |
| 36 | + ~/.cargo/git |
| 37 | + target |
| 38 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} |
| 39 | + - name: Lint |
| 40 | + uses: nick-fields/retry@v3 |
| 41 | + with: |
| 42 | + timeout_minutes: 25 |
| 43 | + max_attempts: 3 |
| 44 | + retry_wait_seconds: 15 |
| 45 | + warning_on_retry: false |
| 46 | + command: pre-commit run --all-files --show-diff-on-failure |
| 47 | + |
| 48 | + build: |
| 49 | + name: Build |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: Setup Rust |
| 53 | + uses: hecrj/setup-rust-action@v2 |
| 54 | + with: |
| 55 | + rust-version: stable |
| 56 | + profile: minimal |
| 57 | + - name: Build |
| 58 | + run: cargo build --release --workspace --all-features |
| 59 | + |
| 60 | + unit-tests: |
| 61 | + name: Unit tests |
| 62 | + runs-on: ${{ matrix.runs-on }} |
| 63 | + strategy: |
| 64 | + fail-fast: false |
| 65 | + matrix: |
| 66 | + runs-on: |
| 67 | + - ubuntu-latest |
| 68 | + - macos-latest |
| 69 | + - windows-latest |
| 70 | + steps: |
| 71 | + - name: Setup Rust |
| 72 | + uses: hecrj/setup-rust-action@v2 |
| 73 | + with: |
| 74 | + rust-version: stable |
| 75 | + profile: minimal |
| 76 | + - name: Cache dependencies |
| 77 | + uses: actions/cache@v4 |
| 78 | + with: |
| 79 | + path: | |
| 80 | + ~/.cargo/registry |
| 81 | + ~/.cargo/git |
| 82 | + target |
| 83 | + key: ${{ runner.os }}-cargo-unit-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} |
| 84 | + - name: Run unit tests |
| 85 | + run: cargo test |
| 86 | + |
| 87 | + test-release: |
| 88 | + needs: |
| 89 | + - qa |
| 90 | + - unit-tests |
| 91 | + - build |
| 92 | + if: | |
| 93 | + '${{ github.event.pull_request.user.login }}' == 'mondeja' || |
| 94 | + startsWith(github.ref, 'refs/tags/') || |
| 95 | + github.ref == 'refs/heads/master' |
| 96 | + name: Test release |
| 97 | + runs-on: ubuntu-latest |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v4 |
| 100 | + - name: Setup Rust |
| 101 | + uses: hecrj/setup-rust-action@v2 |
| 102 | + - name: Publish |
| 103 | + run: | |
| 104 | + cargo login ${{ secrets.CRATES_TOKEN }} |
| 105 | + cargo publish -v --dry-run |
| 106 | +
|
| 107 | + release: |
| 108 | + if: startsWith(github.ref, 'refs/tags/') |
| 109 | + name: Release heldger-fmt |
| 110 | + needs: |
| 111 | + - test-release |
| 112 | + runs-on: ubuntu-latest |
| 113 | + steps: |
| 114 | + - uses: actions/checkout@v4 |
| 115 | + - name: Setup Rust |
| 116 | + uses: hecrj/setup-rust-action@v2 |
| 117 | + - name: Publish |
| 118 | + run: | |
| 119 | + cargo login ${{ secrets.CRATES_TOKEN }} |
| 120 | + cargo publish -v |
| 121 | +
|
| 122 | + create-release: |
| 123 | + if: startsWith(github.ref, 'refs/tags/') |
| 124 | + name: Create release |
| 125 | + needs: |
| 126 | + - release |
| 127 | + permissions: |
| 128 | + contents: write |
| 129 | + runs-on: ubuntu-latest |
| 130 | + steps: |
| 131 | + - uses: actions/checkout@v4 |
| 132 | + - name: Get tag metadata |
| 133 | + id: tag |
| 134 | + run: | |
| 135 | + TAG_TITLE=${GITHUB_REF#refs/*/} |
| 136 | + echo "title=$TAG_TITLE" >> $GITHUB_OUTPUT |
| 137 | + - name: Create release |
| 138 | + uses: softprops/action-gh-release@v2 |
| 139 | + env: |
| 140 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + with: |
| 142 | + name: ${{ steps.tag.outputs.title }} |
| 143 | + tag_name: ${{ steps.tag.outputs.title }} |
| 144 | + body: | |
| 145 | + See [CHANGELOG](https://github.com/mondeja/hledger-fmt/blob/master/CHANGELOG.md). |
| 146 | + draft: false |
| 147 | + prerelease: false |
0 commit comments