Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arathunku committed Mar 23, 2024
0 parents commit 44848cc
Show file tree
Hide file tree
Showing 229 changed files with 14,541,635 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
9 changes: 9 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Used by "mix format"
[
inputs:
["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|> Enum.flat_map(&Path.wildcard(&1, match_dot: true))
|> Enum.reject(&(&1 =~ "lib/ext_fit/profile/")),
# makes it easier to read longer binary matching definitions
line_length: 118
]
132 changes: 132 additions & 0 deletions .github/actions/elixir-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Setup Elixir Project
description: Checks out the code, configures Elixir, fetches dependencies, and manages build caching.
inputs:
elixir-version:
required: true
type: string
description: Elixir version to set up
otp-version:
required: true
type: string
description: OTP version to set up
#################################################################
# Everything below this line is optional.
#
# It's designed to make compiling a reasonably standard Elixir
# codebase "just work," though there may be speed gains to be had
# by tweaking these flags.
#################################################################
build-deps:
required: false
type: boolean
default: true
description: True if we should compile dependencies
build-app:
required: false
type: boolean
default: true
description: True if we should compile the application itself
build-flags:
required: false
type: string
default: '--all-warnings'
description: Flags to pass to mix compile
install-rebar:
required: false
type: boolean
default: true
description: By default, we will install Rebar (mix local.rebar --force).
install-hex:
required: false
type: boolean
default: true
description: By default, we will install Hex (mix local.hex --force).
cache-key:
required: false
type: string
default: 'v1'
description: If you need to reset the cache for some reason, you can change this key.
outputs:
otp-version:
description: "Exact OTP version selected by the BEAM setup step"
value: ${{ steps.beam.outputs.otp-version }}
elixir-version:
description: "Exact Elixir version selected by the BEAM setup step"
value: ${{ steps.beam.outputs.elixir-version }}
runs:
using: "composite"
steps:
- name: Setup elixir
uses: erlef/setup-beam@v1
id: beam
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: Get deps cache
uses: actions/cache@v2
with:
path: deps/
key: deps-${{ inputs.cache-key }}-${{ runner.os }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
deps-${{ inputs.cache-key }}-${{ runner.os }}-
- name: Get build cache
uses: actions/cache@v2
id: build-cache
with:
path: _build/${{env.MIX_ENV}}/
key: build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-
- name: Get Hex cache
uses: actions/cache@v2
id: hex-cache
with:
path: ~/.hex
key: build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-
# In my experience, I have issues with incremental builds maybe 1 in 100
# times that are fixed by doing a full recompile.
# In order to not waste dev time on such trivial issues (while also reaping
# the time savings of incremental builds for *most* day-to-day development),
# I force a full recompile only on builds that we retry.
- name: Clean to rule out incremental build as a source of flakiness
if: github.run_attempt != '1'
run: |
mix deps.clean --all
mix clean
shell: sh

- name: Install Rebar
run: mix local.rebar --force
shell: sh
if: inputs.install-rebar == 'true'

- name: Install Hex
run: mix local.hex --force
shell: sh
if: inputs.install-hex == 'true'

- name: Install Dependencies
run: mix deps.get
shell: sh

# Normally we'd use `mix deps.compile` here, however that incurs a large
# performance penalty when the dependencies are already fully compiled:
# https://elixirforum.com/t/github-action-cache-elixir-always-recompiles-dependencies-elixir-1-13-3/45994/12
#
# Accoring to Jose Valim at the above link `mix loadpaths` will check and
# compile missing dependencies
- name: Compile Dependencies
run: mix loadpaths
shell: sh
if: inputs.build-deps == 'true'

- name: Compile Application
run: mix compile ${{ inputs.build-flags }}
shell: sh
if: inputs.build-app == 'true'
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
time: "12:00"
open-pull-requests-limit: 3
35 changes: 35 additions & 0 deletions .github/workflows/elixir-build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and Test

on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
env:
MIX_ENV: test
strategy:
matrix:
elixir: ["1.16.2"]
otp: ["25.3.2"]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Elixir Project
uses: ./.github/actions/elixir-setup
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
build-flags: --all-warnings --warnings-as-errors

- name: Run Tests
run: mix coveralls.json --warnings-as-errors
if: always()
56 changes: 56 additions & 0 deletions .github/workflows/elixir-dialyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Elixir Type Linting

on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
build:
name: Run Dialyzer
runs-on: ubuntu-latest
env:
MIX_ENV: dev
strategy:
matrix:
elixir: ["1.16.2"]
otp: ["25.3.2"]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Elixir Project
uses: ./.github/actions/elixir-setup
id: beam
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
build-app: false

# Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
# Cache key based on Elixir & Erlang version (also useful when running in matrix)
- name: Restore PLT cache
uses: actions/cache@v3
id: plt_cache
with:
key: plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-${{ hashFiles('**/*.ex') }}
restore-keys: |
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-${{ hashFiles('**/*.ex') }}
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-
path: priv/plts

# Create PLTs if no cache was found.
# Always rebuild PLT when a job is retried
# (If they were cached at all, they'll be updated when we run mix dialyzer with no flags.)
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true' || github.run_attempt != '1'
run: mix dialyzer --plt

- name: Run Dialyzer
run: mix dialyzer --format github
47 changes: 47 additions & 0 deletions .github/workflows/elixir-quality-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Elixir Quality Checks

on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
quality_checks:
name: Formatting, and Unused Deps
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ["1.16.2"]
otp: ["25.3.2"]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Elixir Project
uses: ./.github/actions/elixir-setup
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
build-app: false

- name: Check for unused deps
run: mix deps.unlock --check-unused
- name: Check code formatting
run: mix format --check-formatted
# Check formatting even if there were unused deps so that
# we give devs as much feedback as possible & save some time.
if: always()
# - name: Run Credo
# run: mix credo suggest --min-priority=normal
# # Run Credo even if formatting or the unused deps check failed
# if: always()
# - name: Check for compile-time dependencies
# run: mix xref graph --label compile-connected --fail-above 0
# if: always()
# - name: Check for security vulnerabilities in Phoenix project
# run: mix sobelow
# if: always()
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
ext_fit-*.tar

# Temporary files, for example, from tests.
/tmp/

# dialyzer
priv/plts
2 changes: 2 additions & 0 deletions .iex.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alias SteadyVolume.Training
IEx.configure(inspect: [charlists: :as_lists])
3 changes: 3 additions & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/ext_fit/profile
priv/*.csv
test/support/files
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

<!-- ### Bug fixes -->
<!-- ### Enhancements -->
<!-- ### Backwards incompatible changes -->

## 0.1.0 (2024-03-23)

Init release
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing to ExtFit

## Setup

### Local repository

```sh
# use your own fork
$ git clone [email protected]:arathunku/ext_fit.git
$ cd ext_fit
$ mix deps.get
# ensure everything works
$ mix test
# do your changes
$ mix check
```

### Updating to new SDK

Requires [`Nix` package manager](https://nixos.org/).

1. Get new SDK from [developer.garmin.com](https://developer.garmin.com/fit/download/)
1. Save `.zip` in "sdks/" directory and unzip it next to it with `fit-sdk-{{version}}`
1. Run `scripts/profile-xlsx-as-csv`. This uses LibreOffice to convert `xlsx` to `csv`
1. Update version in `scripts/gen-profile`
1. Generate new profile files with `scripts/gen-profile`

### Add new test FIT files

Requires [`Nix` package manager](https://nixos.org/).

1. Add new file to `test/support/files`
1. Please use name {{YYYY}}-{{MM}}-{{DD}}-{{company}}-{{device}}-{{context}}.fit where date
should _mostly_ match date when the activity was recorded
1. Optional:
- install [fitdecode](https://github.com/polyvertex/fitdecode) for `fitjson` command
- install [fitdump](https://github.com/dtcooper/python-fitparse) for `fitdump` command

1. Run `scripts/generate-dumps-for-test-files`, this will use official fit2csv tool to dump `.csv` file,
Loading

0 comments on commit 44848cc

Please sign in to comment.