chore(deps): update github artifact actions to v4 (#525) #267
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
name: Build & Push | |
on: | |
push: | |
branches: | |
- master | |
env: | |
IMAGE_NAME: robbb | |
jobs: | |
# Push image to GitHub Packages. | |
# See also https://docs.docker.com/docker-hub/builds/ | |
push: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
strategy: | |
max-parallel: 1 | |
matrix: | |
profile: | |
- debug | |
- release | |
include: | |
- profile: release | |
cargo_flags: "--release" | |
cargo_env: "" | |
- profile: debug | |
cargo_flags: "" | |
cargo_env: "RUSTFLAGS='-C debuginfo=0'" | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Rust version | |
id: rust-version | |
run: | | |
echo "::set-output name=rust_version::$(rustc --version)" | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ matrix.profile }} ${{ runner.os }} ${{ steps.rust-version.outputs.rust_version }} ${{ hashFiles('Cargo.lock') }} ${{ hashFiles('src/**') }} | |
restore-keys: | | |
${{ matrix.profile }} ${{ runner.os }} ${{ steps.rust-version.outputs.rust_version }} ${{ hashFiles('Cargo.lock') }} | |
- name: Log into registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Build and push image | |
env: | |
DOCKER_BUILDKIT: 1 | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:${{ github.sha }}-${{ matrix.profile }} | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
echo IMAGE_ID=$IMAGE_ID | |
mkdir artifacts | |
# prebuild docker image | |
touch artifacts/robbb | |
docker build -f Dockerfile artifacts >/dev/null 2>/dev/null & | |
prebuild_pid=$! | |
ROBBB_PROFILE=${{ matrix.profile }} \ | |
ROBBB_COMMIT_HASH="$(git log --format='%H' -n 1 HEAD)" \ | |
ROBBB_COMMIT_MSG="$(git log --format='%s' -n 1 HEAD)" \ | |
${{ matrix.cargo_env }} \ | |
cargo build ${{ matrix.cargo_flags }} --locked & | |
cargo_pid=$! | |
wait $prebuild_pid $cargo_pid | |
cp target/${{ matrix.profile }}/robbb artifacts/ | |
docker build -t $IMAGE_ID -f Dockerfile artifacts/ | |
docker push $IMAGE_ID |