Skip to content

Commit c6030be

Browse files
committed
* Added github workflow + scripts for backend
1 parent 67eb6e6 commit c6030be

File tree

7 files changed

+308
-0
lines changed

7 files changed

+308
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Ask a Question
3+
about: Ask a question about this template.
4+
title: ""
5+
labels: question
6+
assignees: ""
7+
---
8+
9+
**Question**
10+
11+
_Please include information such as the following: is your question to clarify an existing resource
12+
or are you asking about something new? what are you trying to accomplish? where have you looked for
13+
answers?_
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Report a Bug
3+
about: Report a problem with this template.
4+
title: ""
5+
labels: bug
6+
assignees: ""
7+
---
8+
9+
**Description**
10+
11+
_Tell us what happened. In particular, be specific about any changes you made to this template.
12+
Ideally, provide a link to your project's GitHub repository. Please note that we are not able to
13+
support all conceivable changes to this template project, but the more information you are able to
14+
provide the more equipped we will be to help._
15+
16+
**Steps to Reproduce**
17+
18+
_Replace the example steps below with actual steps to reproduce the bug you're reporting._
19+
20+
1. Go to '...'
21+
2. Click on '....'
22+
3. Scroll down to '....'
23+
4. See error
24+
25+
**Expected vs. Actual Behavior**
26+
27+
_What did you expect to happen after you followed the steps you described in the last section? What
28+
actually happened?_
29+
30+
**Environment**
31+
32+
_Describe the environment in which you encountered this bug. Use the list below as a starting point
33+
and add additional information if you think it's relevant._
34+
35+
- Operating system:
36+
- Template version/tag:
37+
- Rust version (run `rustup show`):
38+
39+
**Logs, Errors or Screenshots**
40+
41+
_Please provide the text of any logs or errors that you experienced; if
42+
applicable, provide screenshots to help illustrate the problem._
43+
44+
**Additional Information**
45+
46+
_Please add any other details that you think may help us solve your problem._
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Suggest a Feature
3+
about: Suggest a new feature or an improvement to an existing feature for this template.
4+
title: ""
5+
labels: enhancement
6+
assignees: ""
7+
---
8+
9+
**Motivation**
10+
11+
_Describe the need or frustration that motivated you to make this suggestion. Please note that the
12+
goal of this project is to provide a general-purpose template project, so please take care when
13+
suggesting features that may be specific to a particular use case._
14+
15+
**Suggested Solution**
16+
17+
_Describe your suggested solution to the need or frustration that you are experiencing._
18+
19+
**Alternatives**
20+
21+
_Describe any alternative solutions or features you considered and why you believe your suggested
22+
solution is preferable._
23+
24+
**Additional Information**
25+
26+
_Provide any additional information that you believe may help us evaluate your suggestion._

.github/scripts/free_disk_space.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
get_available_space() {
4+
echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}')
5+
}
6+
7+
BEFORE_SPACE=$(get_available_space)
8+
9+
# REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
10+
echo "Removing large packages"
11+
sudo apt-get remove -y '^dotnet-.*'
12+
sudo apt-get remove -y 'php.*'
13+
sudo apt-get remove -y '^mongodb-.*'
14+
sudo apt-get remove -y '^mysql-.*'
15+
sudo apt-get remove -y \
16+
azure-cli \
17+
google-cloud-sdk \
18+
hhvm \
19+
google-chrome-stable \
20+
firefox \
21+
powershell \
22+
mono-devel \
23+
libgl1-mesa-dri
24+
sudo apt-get autoremove -y
25+
sudo apt-get clean
26+
27+
# REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
28+
echo "Removing large directories"
29+
sudo rm -rf /usr/share/dotnet
30+
sudo rm -rf /usr/local/graalvm
31+
sudo rm -rf /usr/local/.ghcup /opt/ghc
32+
sudo rm -rf /usr/local/share/powershell
33+
sudo rm -rf /usr/local/share/chromium
34+
sudo rm -rf /usr/local/lib/android
35+
sudo rm -rf /usr/local/lib/node_modules
36+
37+
# REF: https://github.com/actions/runner-images/issues/2875#issuecomment-1163392159
38+
echo "Removing tool cache"
39+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
40+
41+
echo "Removing swap storage"
42+
sudo swapoff -a
43+
sudo rm -f /mnt/swapfile
44+
45+
echo "Finding space freed up"
46+
AFTER_SPACE=$(get_available_space)
47+
printf "%'.f\n" $((AFTER_SPACE - BEFORE_SPACE))
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: "Check Backend on Pull Request"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
- main
8+
paths:
9+
- "backend/**/*.rs"
10+
- "backend/**/Cargo.toml"
11+
- "backend/**/Cargo.lock"
12+
- "backend/rust-toolchain.toml"
13+
- "backend/rustfmt.toml"
14+
- ".github/workflows/*.yml"
15+
push:
16+
branches:
17+
- develop
18+
19+
# Ensures only one build is run per branch, unless pushing to develop
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/develop' && github.run_number || github.ref }}
22+
cancel-in-progress: true
23+
24+
env:
25+
CARGO_ARGS: ${{ github.ref == 'refs/heads/develop' && '--release' || '' }}
26+
CARGO_TERM_COLOR: always
27+
SKIP_WASM_BUILD: 1
28+
RUST_NIGHTLY_VERSION: 2024-11-19
29+
30+
defaults:
31+
run:
32+
working-directory: "backend"
33+
34+
jobs:
35+
fmt:
36+
if: ${{ !startsWith(github.head_ref, 'release/') }}
37+
name: Rustfmt
38+
runs-on: ubuntu-latest
39+
continue-on-error: false
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Install nightly toolchain
44+
uses: dtolnay/rust-toolchain@master
45+
with:
46+
targets: "wasm32-unknown-unknown"
47+
components: "rustfmt"
48+
toolchain: "nightly-${{env.RUST_NIGHTLY_VERSION}}"
49+
50+
# some settings are only available in nightly.
51+
- run: cargo +nightly-$RUST_NIGHTLY_VERSION fmt --all -- --check
52+
53+
lint:
54+
if: ${{ !startsWith(github.head_ref, 'release/') }}
55+
name: Clippy
56+
runs-on: ubuntu-latest
57+
continue-on-error: false
58+
steps:
59+
- uses: actions/checkout@v4
60+
- run: ./../.github/scripts/free_disk_space.sh
61+
- run: sudo apt-get install -y protobuf-compiler
62+
- uses: actions/cache@v4
63+
with:
64+
path: |
65+
~/.cargo/bin/
66+
~/.cargo/registry/index/
67+
~/.cargo/registry/cache/
68+
~/.cargo/git/db/
69+
target/
70+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
71+
restore-keys: ${{ runner.os }}-cargo-lint-
72+
- run: cargo clippy --all-features --all-targets ${{ env.CARGO_ARGS }} -- -D warnings
73+
74+
test:
75+
if: ${{ !startsWith(github.head_ref, 'release/') }}
76+
name: Test
77+
runs-on: ubuntu-latest
78+
continue-on-error: false
79+
steps:
80+
- uses: actions/checkout@v4
81+
- run: ./../.github/scripts/free_disk_space.sh
82+
- run: sudo apt-get install -y protobuf-compiler
83+
- uses: actions/cache@v4
84+
with:
85+
path: |
86+
~/.cargo/bin/
87+
~/.cargo/registry/index/
88+
~/.cargo/registry/cache/
89+
~/.cargo/git/db/
90+
target/
91+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
92+
restore-keys: ${{ runner.os }}-cargo-test-
93+
- run: cargo test --all-features --all-targets ${{ env.CARGO_ARGS }}
94+
95+
check-wasm:
96+
if: ${{ !startsWith(github.head_ref, 'release/') }}
97+
name: Check WASM build
98+
runs-on: ubuntu-latest
99+
continue-on-error: false
100+
steps:
101+
- uses: actions/checkout@v4
102+
- run: ./../.github/scripts/free_disk_space.sh
103+
- run: sudo apt-get install -y protobuf-compiler
104+
- uses: actions/cache@v4
105+
with:
106+
path: |
107+
~/backend/.cargo/bin/
108+
~/backend/.cargo/registry/index/
109+
~/backend/.cargo/registry/cache/
110+
~/backend/.cargo/git/db/
111+
~/backend/target/
112+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
113+
restore-keys: ${{ runner.os }}-cargo-lint-
114+
- run: ./scripts/run_for_all_no_std_crates.sh check --no-default-features --target=wasm32-unknown-unknown
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
2+
name: "Cleanup caches by a branch"
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
cleanup:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- run: |
14+
gh extension install actions/gh-actions-cache
15+
16+
REPO=${{ github.repository }}
17+
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
18+
19+
echo "Fetching list of cache key"
20+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
21+
22+
## Setting this to not fail the workflow while deleting cache keys.
23+
set +e
24+
echo "Deleting caches..."
25+
for cacheKey in $cacheKeysForPR
26+
do
27+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
28+
done
29+
echo "Done"
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# Useful for checking individual crates for correctness, i.e., if they compile to wasm.
4+
#
5+
# Example usage: ./scripts/run_for_all_no_std_crates.sh check --no-default-features --target=wasm32-unknown-unknown
6+
7+
set -e
8+
9+
COMMAND=$1
10+
shift
11+
12+
set -x
13+
14+
find . -name "Cargo.toml" | while read -r CARGO_TOML; do
15+
DIR=$(dirname "$CARGO_TOML")
16+
echo "Checking in directory: $DIR"
17+
18+
# Skip the loop if the crate does not have a feature `std`
19+
if ! grep -q "\[features\]" "$CARGO_TOML" || ! grep -q "std = \[" "$CARGO_TOML"; then
20+
echo "Feature 'std' not found in $CARGO_TOML. Skipping."
21+
continue
22+
fi
23+
24+
if grep -q "\[features\]" "$CARGO_TOML" && grep -q "runtime-benchmarks = \[" "$CARGO_TOML"; then
25+
echo "Feature 'runtime-benchmarks' found, adding this feature."
26+
cargo $COMMAND $@ --features runtime-benchmarks --manifest-path "$CARGO_TOML"
27+
else
28+
echo "Feature 'runtime-benchmarks' not found, running command without this feature"
29+
cargo $COMMAND $@ --manifest-path "$CARGO_TOML";
30+
fi
31+
done

0 commit comments

Comments
 (0)