Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 99 additions & 37 deletions .github/workflows/check_lint_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ on:
tags:
- '*'
workflow_dispatch:
inputs:
base_branch:
description: "Base branch to diff against (only used when cargo_deny_check=auto)"
type: string
default: master
cargo_deny_check:
description: "Run or skip the `cargo deny` step"
type: choice
options:
- auto
- force-run
- force-skip
default: auto

name: Check, Lint, Build

env:
CARGO_TERM_COLOR: always
ELECTRS_VERSION: v3.2.0

jobs:
check-lint:
Expand All @@ -28,27 +42,83 @@ jobs:
toolchain: nightly
components: rustfmt, clippy

- name: Rust Cache
- name: Restore Rust cache
id: restore-rust-cache
uses: Swatinem/rust-cache@v2.9.1
with:
cache-all-crates: "true"
prefix-key: "v0-rust-nightly"
save-if: "false"
shared-key: release-x86_64-unknown-linux-gnu

- name: Save Rust cache
if: steps.restore-rust-cache.outputs.cache-hit != 'true'
uses: Swatinem/rust-cache@v2.9.1
with:
shared-key: x86_64-unknown-linux-gnu
cache-all-crates: "true"
lookup-only: "true"
prefix-key: "v0-rust-nightly"
shared-key: release-x86_64-unknown-linux-gnu

- name: Rustfmt
run: cargo fmt --all -- --check

- name: Cargo check
run: cargo check --all-targets --all-features
run: cargo check --release --all-targets --all-features

- name: Clippy
run: cargo clippy --all-targets --all-features
run: cargo clippy --release --all-targets --all-features

- name: Check changed files
id: changed-files
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.cargo_deny_check == 'auto')
uses: dorny/paths-filter@v4
with:
filters: |
cargo_lock:
- 'Cargo.lock'
deny_toml:
- 'deny.toml'

- name: Deny
if: >-
(github.event_name == 'pull_request' && (steps.changed-files.outputs.cargo_lock == 'true' || steps.changed-files.outputs.deny_toml == 'true')) ||
(github.event_name == 'workflow_dispatch' && inputs.cargo_deny_check == 'force-run') ||
(github.event_name == 'workflow_dispatch' && inputs.cargo_deny_check == 'auto' && (steps.changed-files.outputs.cargo_lock == 'true' || steps.changed-files.outputs.deny_toml == 'true'))
uses: EmbarkStudios/cargo-deny-action@v2

cache-electrs:
name: Build electrs if not cached
runs-on: ubuntu-latest
steps:
- name: Check cache
id: check-cache
uses: actions/cache/restore@v6
with:
lookup-only: true
path: ${{ runner.temp }}/electrs/target/release/electrs
key: electrs-${{ env.ELECTRS_VERSION }}

- name: Build electrs
if: steps.check-cache.outputs.cache-hit != 'true'
run: |
git clone --branch ${{ env.ELECTRS_VERSION }} --depth 1 https://github.com/mempool/electrs.git ${{ runner.temp }}/electrs
pushd ${{ runner.temp }}/electrs
cargo build --locked --release
popd

- name: Save cache
if: steps.check-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: ${{ runner.temp }}/electrs/target/release/electrs
key: electrs-${{ env.ELECTRS_VERSION }}


integration-test:
name: Integration test
runs-on: ubuntu-latest
needs: [check-lint]
needs: [cache-electrs, check-lint]
steps:
- name: Download latest bitcoin-patched
run: |
Expand Down Expand Up @@ -82,41 +152,31 @@ jobs:
chmod +x bip300301-enforcer
popd

- name: Checkout electrs
run: |
pushd ..
git clone https://github.com/mempool/electrs.git
popd

- name: Install latest nightly toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
target: x86_64-pc-windows-gnu

- name: Rust Cache (electrs)
uses: Swatinem/rust-cache@v2.9.1
- name: Restore electrs from cache
uses: actions/cache/restore@v6
with:
prefix-key: "v0-rust-electrs"
workspaces: ../electrs -> target

- name: Install electrs
run: |
pushd ../electrs
cargo build --locked --release
popd
fail-on-cache-miss: true
path: ${{ runner.temp }}/electrs/target/release/electrs
key: electrs-${{ env.ELECTRS_VERSION }}

- uses: actions/checkout@v6
with:
submodules: "recursive"

- name: Install latest nightly toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly

- name: Rust Cache
uses: Swatinem/rust-cache@v2.9.1
with:
shared-key: x86_64-unknown-linux-gnu
cache-all-crates: "true"
prefix-key: "v0-rust-nightly"
shared-key: release-x86_64-unknown-linux-gnu

- name: Build (release)
run: cargo build --release
run: cargo build --release --bin photon_app --example integration_tests

- name: Run integration tests
id: runIntegrationTests
Expand All @@ -125,9 +185,9 @@ jobs:
export BITCOIND='../bitcoin-patched-bins/bitcoind'
export BITCOIND_UNPATCHED='../bitcoin-unpatched-bins/bitcoind'
export BITCOIN_CLI='../bitcoin-patched-bins/bitcoin-cli'
export ELECTRS='../electrs/target/release/electrs'
export ELECTRS='${{ runner.temp }}/electrs/target/release/electrs'
export PHOTON_APP='target/release/photon_app'
cargo run --release --example integration_tests
target/release/examples/integration_tests

test-build-release:
strategy:
Expand Down Expand Up @@ -156,6 +216,10 @@ jobs:
contents: write
timeout-minutes: 20
steps:
- name: Install windows-specific deps
run: sudo apt install mingw-w64
if: ${{ matrix.name == 'x86_64-pc-windows-gnu' }}

- uses: actions/checkout@v6
with:
submodules: recursive
Expand All @@ -169,11 +233,9 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@v2.9.1
with:
key: ${{ matrix.name }}

- name: Install windows-specific deps
run: sudo apt install mingw-w64
if: ${{ matrix.name == 'x86_64-pc-windows-gnu' }}
cache-all-crates: "true"
prefix-key: "v0-rust-nightly"
shared-key: ${{ matrix.name }}

- name: Test
run: cargo test --tests
Expand Down Expand Up @@ -294,4 +356,4 @@ jobs:
password: ${{ secrets.RELEASES_SERVER_PW }}
port: 22
source: 'L2-S99-Photon-latest-*.zip'
target: '/var/www/html/'
target: '/var/www/html/'
31 changes: 31 additions & 0 deletions .github/workflows/clean-gh-actions-caches-closed-pr-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Evict GitHub actions caches for closed/merged PR branches
on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
permissions:
actions: write
runs-on: ubuntu-latest
steps:
- name: Cleanup
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
run: |
echo "Fetching list of cache keys"
BRANCH_CACHE_KEYS=$(gh cache list --ref $BRANCH --json id --jq '.[].id')

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for CACHE_KEY in $BRANCH_CACHE_KEYS
do
echo "Deleting cache ${CACHE_KEY}"
gh cache delete $CACHE_KEY
done
echo "Done"
31 changes: 31 additions & 0 deletions .github/workflows/clean-gh-actions-caches-nightly-rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Evict stale nightly Rust caches
on:
schedule:
# every 12 hours
- cron: "0 */12 * * *"
workflow_dispatch:

jobs:
cleanup:
permissions:
actions: write
runs-on: ubuntu-latest
steps:
- name: Delete nightly Rust caches older than 48h
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
CUTOFF=$(date -u -d '48 hours ago' +%s)

CACHE_IDS=$(gh cache list --repo "$REPO" --limit 500 \
--json id,key,createdAt |
jq -r --argjson cutoff "$CUTOFF" \
'.[] | select(.key | startswith("v0-rust-nightly"))
| select((.createdAt | sub("\\.[0-9]+"; "") | fromdateiso8601) < $cutoff)
| .id')

for CACHE_ID in $CACHE_IDS; do
echo "Deleting cache $CACHE_ID"
gh cache delete "$CACHE_ID" --repo "$REPO"
done
Loading
Loading