diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml new file mode 100644 index 00000000..42fcf24b --- /dev/null +++ b/.github/workflows/build-workflow.yml @@ -0,0 +1,39 @@ +on: + workflow_call: + inputs: + os: + type: string + default: '["ubuntu-latest", "windows-latest", "macos-latest"]' + release: + type: boolean + default: false + enable-caching: + type: boolean + default: false + upload-artifacts: + type: boolean + default: false + +jobs: + build: + name: Build project + strategy: + matrix: + os: ${{ fromJSON(inputs.os) }} + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: cache + uses: Swatinem/rust-cache@v2 + if: ${{ inputs.enable-caching }} && matrix.os == 'ubuntu-latest' + with: + shared-key: "build-files" + - name: Build unimarkup + run: cargo build ${{ inputs.release && '--release' || '' }} + - name: upload archive + if: ${{ inputs.upload-artifacts }} + uses: actions/upload-artifact@v4 + with: + name: unimarkup-${{matrix.os}} + path: ./target/release/unimarkup${{ matrix.os == 'windows-latest' && '.exe' || '' }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 080977e6..b5be5069 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -3,13 +3,21 @@ on: branches: - main +permissions: + contents: write + pull-requests: write + name: Release Please jobs: release-please: runs-on: ubuntu-latest + outputs: + release-created: ${{ steps.release.outputs.release_created }} + tag-name: ${{ steps.release.outputs.tag_name }} steps: - uses: GoogleCloudPlatform/release-please-action@v2 + id: release with: release-type: rust package-name: unimarkup-rs @@ -22,3 +30,33 @@ jobs: {"type":"arch","section":"Architecture/Refactor","hidden":false}, {"type":"chore","section":"Miscellaneous","hidden":true} ] + + release-build: + name: Build unimarkup release + needs: release-please + if: ${{ needs.release-please.outputs.release-created }} + uses: ./.github/workflows/build-workflow.yml + with: + release: true + upload-artifacts: true + + upload-executables: + runs-on: ubuntu-latest + needs: + - release-please + - release-build + if: ${{ needs.release-please.outputs.release-created }} + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + - name: Upload Release Artifacts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository_owner }}/${{ github.event.repository.name }} + run: | + ls -la + mv -v unimarkup-ubuntu-latest/unimarkup ./unimarkup-linux + mv -v unimarkup-windows-latest/unimarkup.exe ./unimarkup-win.exe + mv -v unimarkup-macos-latest/unimarkup ./unimarkup-macos + ls -la + gh release upload ${{ needs.release-please.outputs.tag-name }} ./unimarkup-linux ./unimarkup-win.exe ./unimarkup-macos diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 59d87254..471ee3d7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,24 +10,34 @@ env: CARGO_TERM_COLOR: always jobs: + build: + name: Build unimarkup on all systems + uses: ./.github/workflows/build-workflow.yml + with: + os: ${{ github.ref == 'refs/heads/main' && '["ubuntu-latest", "windows-latest", "macos-latest"]' || '["ubuntu-latest"]'}} + enable-caching: false + format: name: Check Formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run cargo fmt - run: cargo fmt -- --check + - uses: actions/checkout@v4 + - name: Run cargo fmt + run: cargo fmt -- --check lint: name: Run Linter (clippy) runs-on: ubuntu-latest - needs: format + needs: [ format, build ] steps: - - uses: actions/checkout@v2 - - name: Run linter - run: cargo clippy -- -D warnings + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + with: + shared-key: "build-files" + - name: Run linter + run: cargo clippy -- -D warnings test: name: Run Tests @@ -35,6 +45,9 @@ jobs: needs: lint steps: - - uses: actions/checkout@v2 - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + with: + shared-key: "build-files" + - name: Run tests + run: cargo test --verbose