Rust Workflow #66
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
--- | |
# copilot helped a lot here | |
name: Rust Workflow | |
on: | |
pull_request: | |
branches: ["main", "refactor"] | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
# Allows manual triggering | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
BUILD_TARGET: [release] | |
outputs: | |
release_built: ${{ steps.set-output.outputs.release_built }} | |
steps: | |
- name: ⚡ Cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- uses: actions/checkout@v4 | |
- name: Build binaries in "${{ matrix.BUILD_TARGET }}" mode | |
run: cargo build --profile ${{ matrix.BUILD_TARGET }} | |
- name: Run tests in "${{ matrix.BUILD_TARGET }}" mode | |
run: cargo test --profile ${{ matrix.BUILD_TARGET }} | |
- name: Upload Telegram Bot | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cndk8-telegram-bot | |
path: target/${{ matrix.BUILD_TARGET }}/telegram | |
- name: Upload hello app | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cndk8-hello | |
path: target/${{ matrix.BUILD_TARGET }}/cndk8 | |
publish: | |
if: github.ref == 'refs/heads/main' | |
# Check if the branch is main | |
environment: publishing | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: ⚡ Cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Set token environment variable | |
run: echo "X_TOKEN=${{ secrets.X_TOKEN }}" >> $GITHUB_ENV | |
- name: Display structure of downloaded files | |
run: ls -lahR && pwd | |
- name: Login into crates.io | |
run: cargo login ${{ secrets.CRATES_IO }} | |
- uses: actions/checkout@v4 | |
- name: Build binaries in "release" mode | |
run: cargo build -r | |
- name: Display files after download | |
run: ls -lahR && pwd | |
- name: "Package for crates.io" | |
run: cargo package | |
- name: "Publish to crates.io" | |
run: cargo publish | |
- name: Download hello app | |
uses: actions/download-artifact@v4 | |
with: | |
name: cndk8-hello | |
path: ./cndk8-hello | |
- name: Publish hello app to GitHub Packages | |
run: | | |
curl -u "${{ github.actor }}:${{ secrets.GH_TOKEN }}" \ | |
-X POST "https://uploads.github.com/repos/${{ github.repository }}/releases/assets?name=cndk8-hello.tar.gz" \ | |
--header "Content-Type: application/gzip" \ | |
--data-binary @./cndk8-hello/cndk8 |