1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2025-03-16 13:28:17 +00:00
attic/.github/workflows/build.yml

105 lines
3.5 KiB
YAML
Raw Normal View History

2022-12-31 17:01:07 -07:00
name: Build
on:
pull_request:
push:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
2022-12-31 17:01:07 -07:00
jobs:
tests:
strategy:
matrix:
os:
- ubuntu-latest
2024-07-09 12:25:36 -04:00
- macos-latest
nix:
- "2.20"
- "2.24"
- "default"
2022-12-31 17:01:07 -07:00
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
2022-12-31 17:01:07 -07:00
steps:
2023-12-18 14:50:33 -07:00
- uses: actions/checkout@v4.1.1
2022-12-31 17:01:07 -07:00
2024-08-30 12:32:10 -04:00
- name: Install current Bash on macOS
if: runner.os == 'macOS'
run: |
command -v brew && brew install bash || true
2023-12-18 14:50:33 -07:00
- uses: DeterminateSystems/nix-installer-action@v9
continue-on-error: true # Self-hosted runners already have Nix installed
2023-01-02 22:12:56 -07:00
- name: Install Attic
run: |
if ! command -v attic &> /dev/null; then
./.github/install-attic-ci.sh
fi
2023-01-02 22:12:56 -07:00
- name: Configure Attic
run: |
: "${ATTIC_SERVER:=https://staging.attic.rs/}"
: "${ATTIC_CACHE:=attic-ci}"
echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV
2023-01-02 22:12:56 -07:00
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN"
attic use "$ATTIC_CACHE"
2023-01-02 22:12:56 -07:00
env:
ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
2023-01-02 22:12:56 -07:00
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
2022-12-31 17:01:07 -07:00
- name: Cache dev shell
run: |
.ci/cache-shell.sh
2023-01-02 22:12:56 -07:00
system=$(nix-instantiate --eval -E 'builtins.currentSystem')
echo system=$system >>$GITHUB_ENV
- name: Run unit tests
run: |
.ci/run just ci-unit-tests ${{ matrix.nix }}
2023-01-02 22:12:56 -07:00
- name: Build WebAssembly crates
if: runner.os == 'Linux'
run: |
.ci/run just ci-build-wasm
2023-01-02 22:12:56 -07:00
# TODO: Just take a diff of the list of store paths, also abstract all of this out
- name: Push build artifacts
run: |
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
if [ -n "$ATTIC_TOKEN" ]; then
nix build --no-link --print-out-paths -L \
.#internalMatrix."$system".\"${{ matrix.nix }}\".attic-tests \
.#internalMatrix."$system".\"${{ matrix.nix }}\".cargoArtifacts \
| xargs attic push "ci:$ATTIC_CACHE"
2023-01-02 22:12:56 -07:00
fi
- name: Log in to the Container registry
2023-12-18 14:50:33 -07:00
uses: docker/login-action@v3.0.0
if: runner.os == 'Linux' && github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push build container image
if: runner.os == 'Linux' && github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
continue-on-error: true
run: |
IMAGE_ID=ghcr.io/${IMAGE_NAME}
TARBALL=$(nix build --json .#attic-server-image | jq -r '.[].outputs.out')
BRANCH=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
TAG="${{ github.sha }}"
[[ "${{ github.ref }}" == "refs/tags/"* ]] && TAG=$(echo $BRANCH | sed -e 's/^v//')
docker load < ${TARBALL}
echo IMAGE_ID=$IMAGE_ID
echo TAG=$TAG
docker tag attic-server:main "${IMAGE_ID}:${TAG}"
docker push ${IMAGE_ID}:${TAG}
if [ "$BRANCH" == "main" ]; then
TAG="latest"
docker tag attic-server:main "${IMAGE_ID}:${TAG}"
docker push ${IMAGE_ID}:${TAG}
fi