ci: Cache Dependencies for GH Actions

This allows for faster build times as caches are automatically created
pull/6/head
Hamothy 2 years ago committed by GitHub
parent 7b5f0e4a80
commit d19ed9448a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,101 +15,98 @@ on:
- '.github/**' - '.github/**'
jobs: jobs:
install-cross:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 50
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded
repo: cross
matches: ${{ matrix.platform }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v1
with:
name: cross-${{ matrix.platform }}
path: ${{ steps.cross.outputs.install_path }}
strategy:
matrix:
platform: [ linux-musl, apple-darwin ]
windows: windows:
runs-on: windows-latest runs-on: windows-latest
needs: install-cross
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 50
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }}
shell: bash
- run: .github/scripts/build.bash cargo ${{ matrix.target }}
shell: bash
- run: .github/scripts/test.bash cargo ${{ matrix.target }}
shell: bash
strategy: strategy:
matrix: matrix:
channel: [ stable, beta ]
target: target:
- x86_64-pc-windows-gnu - x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc - x86_64-pc-windows-msvc
macos:
runs-on: macos-latest
needs: install-cross
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: - name: Cache Cargo
fetch-depth: 50 uses: actions/cache@v3
- uses: actions/download-artifact@v1
with: with:
name: cross-apple-darwin path: |
path: /usr/local/bin/ ~/.cargo/registry
./target
- run: chmod +x /usr/local/bin/cross # Example key: windows-stable-x86_64-pc-windows-gnu-3k4j234lksjfd9
key: windows-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }} restore-keys: |
- run: .github/scripts/build.bash cross ${{ matrix.target }} windows-stable-${{ matrix.target }}-
- run: .github/scripts/test.bash cross ${{ matrix.target }} windows-stable-
if: matrix.target == 'x86_64-apple-darwin' windows-
- name: Set Rust Channel
run: rustup default stable
shell: bash
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
shell: bash
- name: Build
run: cargo build --target ${{ matrix.target }}
shell: bash
- name: Test
run: cargo test --target ${{ matrix.target }}
shell: bash
macos:
runs-on: macos-latest
strategy: strategy:
matrix: matrix:
channel: [ stable, beta ]
target: target:
- x86_64-apple-darwin - x86_64-apple-darwin
linux:
runs-on: ubuntu-latest
needs: install-cross
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: - name: Cache Cargo
fetch-depth: 50 uses: actions/cache@v3
- name: Download Cross
uses: actions/download-artifact@v1
with: with:
name: cross-linux-musl path: |
path: /tmp/ ~/.cargo/registry
- run: chmod +x /tmp/cross ./target
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }} # Example key: macos-stable-x86_64-apple-darwin-3k4j234lksjfd9
- run: .github/scripts/build.bash /tmp/cross ${{ matrix.target }} key: macos-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- run: .github/scripts/test.bash /tmp/cross ${{ matrix.target }} restore-keys: |
if: | macos-stable-${{ matrix.target }}-
!contains(matrix.target, 'android') && macos-stable-
!contains(matrix.target, 'bsd') && macos-
!contains(matrix.target, 'solaris') && - name: Set Rust Channel
matrix.target != 'armv5te-unknown-linux-musleabi' && run: rustup default stable
matrix.target != 'sparc64-unknown-linux-gnu' - name: Set Rust Target
run: rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --target ${{ matrix.target }}
- name: Test
run: cargo test --target ${{ matrix.target }}
linux:
runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
channel: [ stable, beta ]
target: target:
- x86_64-unknown-linux-gnu - x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl - x86_64-unknown-linux-musl
steps:
- uses: actions/checkout@v3
- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
./target
# Example key: linux-stable-x86_64-unknown-linux-gnu-3k4j234lksjfd9
key: linux-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
linux-stable-${{ matrix.target }}-
linux-stable-
linux-
- name: Set Rust Channel
run: rustup default stable
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --target ${{ matrix.target }}
- name: Test
run: cargo test --target ${{ matrix.target }}

@ -1,143 +1,168 @@
name: deploy
on: on:
push: push:
# Sequence of patterns matched against refs/tags # Sequence of patterns matched against refs/tags
tags: tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
name: deploy
env: env:
BIN: git-view bin: git-view
jobs: jobs:
install-cross:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 50
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded
repo: cross
matches: ${{ matrix.platform }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v1
with:
name: cross-${{ matrix.platform }}
path: ${{ steps.cross.outputs.install_path }}
strategy:
matrix:
platform: [ linux-musl, apple-darwin ]
windows: windows:
runs-on: windows-latest runs-on: windows-latest
needs: install-cross
strategy: strategy:
matrix: matrix:
target: target:
- x86_64-pc-windows-gnu - x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc - x86_64-pc-windows-msvc
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- run: bash .github/scripts/set_rust_version.bash stable ${{ matrix.target }} - name: Cache Cargo
- run: bash .github/scripts/build.bash cargo ${{ matrix.target }} RELEASE uses: actions/cache@v3
- run: | with:
path: |
~/.cargo/registry
./target
# Example key: windows-stable-x86_64-pc-windows-gnu-3k4j234lksjfd9
key: windows-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
windows-stable-${{ matrix.target }}-
windows-stable-
windows-
- name: Set Rust Channel
run: rustup default stable
shell: bash
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
shell: bash
- name: Build Release Binary
run: cargo build --target ${{ matrix.target }} --release
shell: bash
- name: Compress Windows Binary
run: |
cd ./target/${{ matrix.target }}/release/ cd ./target/${{ matrix.target }}/release/
7z a "${{ env.BIN }}.zip" "${{ env.BIN }}.exe" 7z a "${{ env.bin }}-${{ matrix.target }}.zip" "${{ env.bin }}.exe"
mv "${{ env.BIN }}.zip" $GITHUB_WORKSPACE mv "${{ env.bin }}-${{ matrix.target }}.zip" $GITHUB_WORKSPACE
shell: bash shell: bash
- uses: XAMPPRocky/create-release@v1.0.2 - name: Archive Windows Artifact
id: create_release uses: actions/upload-artifact@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- uses: actions/upload-release-asset@v1
id: upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} name: Windows
asset_path: ${{ env.BIN }}.zip path: |
asset_name: ${{ env.BIN }}-${{ matrix.target }}.zip ${{ github.workspace }}/${{ env.bin }}-${{ matrix.target }}.zip
asset_content_type: application/zip
macos: macos:
runs-on: macos-latest runs-on: macos-latest
needs: install-cross
strategy: strategy:
matrix: matrix:
target: target:
- x86_64-apple-darwin - x86_64-apple-darwin
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v1
with:
name: cross-apple-darwin
path: /usr/local/bin/
- run: chmod +x /usr/local/bin/cross
- run: .github/scripts/set_rust_version.bash stable ${{ matrix.target }} steps:
- run: .github/scripts/build.bash cross ${{ matrix.target }} RELEASE - uses: actions/checkout@v3
- run: tar -czvf ${{ env.BIN }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.BIN }} - name: Cache Cargo
- uses: XAMPPRocky/create-release@v1.0.2 uses: actions/cache@v3
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ github.ref }} path: |
release_name: ${{ github.ref }} ~/.cargo/registry
draft: false ./target
prerelease: false # Example key: macos-stable-x86_64-apple-darwin-3k4j234lksjfd9
- uses: actions/upload-release-asset@v1 key: macos-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
id: upload-release-asset restore-keys: |
env: macos-stable-${{ matrix.target }}-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} macos-stable-
macos-
- name: Set Rust Channel
run: rustup default stable
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
- name: Build Release Binary
run: cargo build --target ${{ matrix.target }} --release
- name: Compress macOS Binary
run: tar -czvf ${{ env.bin }}-${{ matrix.target }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.bin }}
- name: Archive macOS Artifact
uses: actions/upload-artifact@v3
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} name: macOS
asset_path: ${{ env.BIN }}.tar.gz path: |
asset_name: ${{ env.BIN }}-${{ matrix.target }}.tar.gz ./${{ env.bin }}-${{ matrix.target }}.tar.gz
asset_content_type: application/gzip
linux: linux:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: install-cross
strategy: strategy:
matrix: matrix:
target: target:
- x86_64-unknown-linux-gnu - x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl - x86_64-unknown-linux-musl
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/download-artifact@v1 - name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
./target
# Example key: linux-stable-x86_64-unknown-linux-gnu-3k4j234lksjfd9
key: linux-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
linux-stable-${{ matrix.target }}-
linux-stable-
linux-
- name: Set Rust Channel
run: rustup default stable
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
- name: Build Release Binary
run: cargo build --target ${{ matrix.target }} --release
- name: Compress Linux Binary
run: tar -czvf ${{ env.bin }}-${{ matrix.target }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.bin }}
- name: Archive Linux Artifact
uses: actions/upload-artifact@v3
with: with:
name: cross-linux-musl name: Linux
path: /tmp/ path: |
- run: chmod +x /tmp/cross ./${{ env.bin }}-${{ matrix.target }}.tar.gz
- run: .github/scripts/set_rust_version.bash stable ${{ matrix.target }} deploy-artifacts:
- run: .github/scripts/build.bash /tmp/cross ${{ matrix.target }} RELEASE needs: [ windows, macos, linux ]
- run: tar -czvf ${{ env.BIN }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.BIN }} runs-on: ubuntu-latest
- uses: XAMPPRocky/create-release@v1.0.2
id: create_release steps:
env: - name: Download Artifacts
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: actions/download-artifact@v3
- name: Display Structure
run: ls -R
- name: Release
uses: softprops/action-gh-release@v1
with: with:
tag_name: ${{ github.ref }} files: |
release_name: ${{ github.ref }} ./Linux/*.tar.gz
draft: false ./macOS/*.tar.gz
prerelease: false ./Windows/*.zip
- name: Upload Release Asset
id: upload-release-asset homebrew:
uses: actions/upload-release-asset@v1 needs: deploy-artifacts
env: runs-on: ubuntu-latest
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Extract Version
run: |
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
- uses: mislav/bump-homebrew-formula-action@v1
if: "!contains(github.ref, '-')" # Skip Pre-Releases
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} create-pullrequest: true
asset_path: ${{ env.BIN }}.tar.gz formula-name: ${{ env.bin }}
asset_name: ${{ env.BIN }}-${{ matrix.target }}.tar.gz formula-path: Formula/${{ env.bin }}.rb
asset_content_type: application/gzip homebrew-tap: sgoudham/homebrew-tap
download-url: https://github.com/sgoudham/${{ env.bin }}/releases/download/${{ steps.extract-version.outputs.tag-name }}/${{ env.bin }}-x86_64-apple-darwin.tar.gz
commit-message: |
{{formulaName}} -> {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW }}

Loading…
Cancel
Save