96 lines
2.8 KiB
YAML
96 lines
2.8 KiB
YAML
name: Gitea Actions Demo
|
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions
|
|
on: [push, pull_request]
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Get Dependencies Index Hash
|
|
uses: https://github.com/KEINOS/gh-action-hash-for-cache@main
|
|
id: hash-dependencies-index
|
|
with:
|
|
path: '**/Cargo.lock'
|
|
|
|
- name: Restore Dependencies
|
|
id: restore-dependencies
|
|
uses: https://github.com/actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.cargo/bin/
|
|
~/.cargo/registry/index/
|
|
~/.cargo/registry/cache/
|
|
~/.cargo/git/db/
|
|
target/
|
|
key: ${{ runner.os }}-cargo-${{ steps.hash-dependencies-index.outputs.hash }}
|
|
|
|
- name: Install Rust
|
|
uses: https://github.com/actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: stable
|
|
override: true
|
|
|
|
- name: Get Commit Tag
|
|
id: tag
|
|
uses: https://github.com/Maxyme/get-release-or-tag@v2
|
|
|
|
- name: Build
|
|
run: cargo build --release
|
|
|
|
- name: Cache Executable Binary
|
|
uses: https://github.com/actions/cache/save@v3
|
|
with:
|
|
path: ./target/release/network-monitor
|
|
key: ${{ runner.os }}-release-${{ steps.tag.outputs.tag }}
|
|
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: catthehacker/ubuntu:act-latest
|
|
needs: build
|
|
|
|
env:
|
|
REGISTRY: git.ivanli.cc
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
steps:
|
|
- name: Get Commit Tag
|
|
id: tag
|
|
uses: https://github.com/Maxyme/get-release-or-tag@v2
|
|
|
|
- id: restore-executable-binary
|
|
name: Cache Executable Binaries
|
|
uses: https://github.com/actions/cache/restore@v3
|
|
with:
|
|
path: ./network-monitor
|
|
key: ${{ runner.os }}-release-${{ steps.tag.outputs.tag }}
|
|
- if: ${{ steps.restore-executable-binary.outputs.cache-hit != 'true' }}
|
|
name: Check if binary exists
|
|
run: echo "missing program"
|
|
|
|
- name: Log in to the Container registry
|
|
uses: https://github.com/docker/login-action@v2
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: https://github.com/docker/metadata-action@v4
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: https://github.com/docker/build-push-action@v4
|
|
env:
|
|
ACTIONS_RUNTIME_TOKEN: ''
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|