chore: migrate to local. (#27)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #27 Co-authored-by: James Harton <james@harton.nz> Co-committed-by: James Harton <james@harton.nz>
This commit is contained in:
parent
18720d5ac4
commit
2b01e70ae1
383
.drone.yml
Normal file
383
.drone.yml
Normal file
|
@ -0,0 +1,383 @@
|
|||
kind: pipeline
|
||||
type: docker
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: restore ASDF cache
|
||||
image: meltwater/drone-cache
|
||||
pull: "always"
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: SECRET_ACCESS_KEY
|
||||
AWS_PLUGIN_PATH_STYLE: true
|
||||
settings:
|
||||
restore: true
|
||||
endpoint:
|
||||
from_secret: S3_ENDPOINT
|
||||
bucket:
|
||||
from_secret: CACHE_BUCKET
|
||||
region: us-east-1
|
||||
path-style: true
|
||||
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
|
||||
mount:
|
||||
- .asdf
|
||||
|
||||
- name: restore build cache
|
||||
image: meltwater/drone-cache
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: SECRET_ACCESS_KEY
|
||||
AWS_PLUGIN_PATH_STYLE: true
|
||||
settings:
|
||||
restore: true
|
||||
endpoint:
|
||||
from_secret: S3_ENDPOINT
|
||||
bucket:
|
||||
from_secret: CACHE_BUCKET
|
||||
region: us-east-1
|
||||
path-style: true
|
||||
cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}'
|
||||
mount:
|
||||
- deps
|
||||
- _build
|
||||
- .hex
|
||||
- .mix
|
||||
- .rebar3
|
||||
|
||||
- name: install dependencies
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
pull: "always"
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
ASDF_DIR: /root/.asdf
|
||||
depends_on:
|
||||
- restore ASDF cache
|
||||
- restore build cache
|
||||
commands:
|
||||
- asdf_install
|
||||
- rm -rf .asdf/downloads
|
||||
- . $ASDF_DIR/asdf.sh
|
||||
- mix local.hex --if-missing --force
|
||||
- mix local.rebar --if-missing --force
|
||||
- mix deps.get
|
||||
- mix deps.compile
|
||||
- mix dialyzer --plt
|
||||
|
||||
- name: store ASDF cache
|
||||
image: meltwater/drone-cache
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: SECRET_ACCESS_KEY
|
||||
AWS_PLUGIN_PATH_STYLE: true
|
||||
depends_on:
|
||||
- install dependencies
|
||||
settings:
|
||||
rebuild: true
|
||||
override: false
|
||||
endpoint:
|
||||
from_secret: S3_ENDPOINT
|
||||
bucket:
|
||||
from_secret: CACHE_BUCKET
|
||||
region: us-east-1
|
||||
path-style: true
|
||||
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
|
||||
mount:
|
||||
- .asdf
|
||||
|
||||
- name: store build cache
|
||||
image: meltwater/drone-cache
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: SECRET_ACCESS_KEY
|
||||
AWS_PLUGIN_PATH_STYLE: true
|
||||
depends_on:
|
||||
- install dependencies
|
||||
settings:
|
||||
rebuild: true
|
||||
override: false
|
||||
endpoint:
|
||||
from_secret: S3_ENDPOINT
|
||||
bucket:
|
||||
from_secret: CACHE_BUCKET
|
||||
region: us-east-1
|
||||
path-style: true
|
||||
cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}'
|
||||
mount:
|
||||
- deps
|
||||
- _build
|
||||
- .hex
|
||||
- .mix
|
||||
- .rebar3
|
||||
|
||||
- name: mix compile
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- install dependencies
|
||||
commands:
|
||||
- asdf mix compile --warnings-as-errors
|
||||
|
||||
- name: mix test
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix test
|
||||
|
||||
- name: mix credo
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix credo --strict
|
||||
|
||||
- name: mix dialyzer
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix dialyzer
|
||||
|
||||
- name: mix hex.audit
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix hex.audit
|
||||
|
||||
- name: mix format
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix format --check-formatted
|
||||
|
||||
- name: mix deps.unlock
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix deps.unlock --check-unused
|
||||
|
||||
- name: mix doctor
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- asdf mix doctor --full
|
||||
|
||||
- name: mix git_ops.check_message
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
depends_on:
|
||||
- mix compile
|
||||
commands:
|
||||
- git log -1 --format=%s > .last_commit_message
|
||||
- asdf mix git_ops.check_message .last_commit_message
|
||||
|
||||
- name: mix git_ops.release
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
depends_on:
|
||||
- mix test
|
||||
- mix credo
|
||||
- mix dialyzer
|
||||
- mix hex.audit
|
||||
- mix format
|
||||
- mix deps.unlock
|
||||
- mix doctor
|
||||
- mix git_ops.check_message
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
ASDF_DIR: /root/.asdf
|
||||
DRONE_TOKEN:
|
||||
from_secret: DRONE_TOKEN
|
||||
commands:
|
||||
- git fetch --tags
|
||||
- . $ASDF_DIR/asdf.sh
|
||||
- mix git_ops.project_info --format=shell > before.env
|
||||
- mix git_ops.release --yes --no-major || true
|
||||
- mix git_ops.project_info --format=shell > after.env
|
||||
- . ./before.env
|
||||
- export OLD_APP_VERSION=$${APP_VERSION}
|
||||
- . ./after.env
|
||||
- export NEW_APP_VERSION=$${APP_VERSION}
|
||||
- if [ "v$${OLD_APP_VERSION}" != "v$${NEW_APP_VERSION}" ]; then
|
||||
- export GIT_URL=$(echo $DRONE_GIT_HTTP_URL | sed -e "s/:\\/\\//:\\/\\/$DRONE_REPO_OWNER:$DRONE_TOKEN@/")
|
||||
- git push $${GIT_URL} "HEAD:${DRONE_COMMIT_REF}" "refs/tags/v$${NEW_APP_VERSION}"
|
||||
- fi
|
||||
|
||||
- name: build artifacts
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
refs:
|
||||
include:
|
||||
- refs/tags/v*
|
||||
depends_on:
|
||||
- mix test
|
||||
- mix credo
|
||||
- mix dialyzer
|
||||
- mix hex.audit
|
||||
- mix format
|
||||
- mix deps.unlock
|
||||
- mix doctor
|
||||
- mix git_ops.check_message
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
ASDF_DIR: /root/.asdf
|
||||
commands:
|
||||
- . $ASDF_DIR/asdf.sh
|
||||
- mix git_ops.project_info --format=shell > app.env
|
||||
- . ./app.env
|
||||
- mkdir artifacts
|
||||
- mix hex.build -o "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar"
|
||||
- gzip "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar"
|
||||
- mix docs
|
||||
- tar zcvf "artifacts/$${APP_NAME}-$${APP_VERSION}-docs.tar.gz" doc/
|
||||
- git tag -l --format='%(contents:subject)' v$${APP_VERSION} > tag_subject
|
||||
- git tag -l --format='%(contents:body)' v$${APP_VERSION} > tag_body
|
||||
|
||||
- name: gitea release
|
||||
image: plugins/gitea-release
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
refs:
|
||||
include:
|
||||
- refs/tags/v*
|
||||
depends_on:
|
||||
- build artifacts
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: DRONE_TOKEN
|
||||
base_url: https://harton.dev
|
||||
files: artifacts/*.tar.gz
|
||||
checksum: sha256
|
||||
title: tag_subject
|
||||
note: tag_body
|
||||
|
||||
- name: docs release
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
refs:
|
||||
include:
|
||||
- refs/tags/v*
|
||||
image: minio/mc
|
||||
environment:
|
||||
S3_ENDPOINT:
|
||||
from_secret: S3_ENDPOINT
|
||||
ACCESS_KEY:
|
||||
from_secret: ACCESS_KEY_ID
|
||||
SECRET_KEY:
|
||||
from_secret: SECRET_ACCESS_KEY
|
||||
depends_on:
|
||||
- build artifacts
|
||||
commands:
|
||||
- mc alias set store $${S3_ENDPOINT} $${ACCESS_KEY} $${SECRET_KEY}
|
||||
- mc mb -p store/docs.harton.nz
|
||||
- mc anonymous set download store/docs.harton.nz
|
||||
- mc mirror --overwrite doc/ store/docs.harton.nz/$${DRONE_REPO}/$${DRONE_TAG}
|
||||
- mc mirror --overwrite doc/ store/docs.harton.nz/$${DRONE_REPO}
|
||||
|
||||
- name: hex release
|
||||
image: harton.dev/james/asdf_container:latest
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
refs:
|
||||
include:
|
||||
- refs/tags/v*
|
||||
depends_on:
|
||||
- build artifacts
|
||||
environment:
|
||||
MIX_ENV: test
|
||||
HEX_HOME: /drone/src/.hex
|
||||
MIX_HOME: /drone/src/.mix
|
||||
REBAR_BASE_DIR: /drone/src/.rebar3
|
||||
ASDF_DATA_DIR: /drone/src/.asdf
|
||||
ASDF_DIR: /root/.asdf
|
||||
HEX_API_KEY:
|
||||
from_secret: HEX_API_KEY
|
||||
commands:
|
||||
- . $ASDF_DIR/asdf.sh
|
||||
- mix hex.publish --yes
|
139
.gitlab-ci.yml
139
.gitlab-ci.yml
|
@ -1,139 +0,0 @@
|
|||
stages:
|
||||
- build
|
||||
- test
|
||||
- release
|
||||
|
||||
variables:
|
||||
MIX_ENV: "test"
|
||||
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/"
|
||||
HEX_HOME: "$CI_PROJECT_DIR/.hex"
|
||||
MIX_HOME: "$CI_PROJECT_DIR/.mix"
|
||||
|
||||
build:
|
||||
image: elixir:latest
|
||||
stage: build
|
||||
cache:
|
||||
key: "$CI_JOB_NAME"
|
||||
paths:
|
||||
- deps
|
||||
- _build
|
||||
- .hex
|
||||
- .mix
|
||||
script:
|
||||
- mix local.hex --force
|
||||
- mix local.rebar --force
|
||||
- mix deps.get
|
||||
- mix deps.compile
|
||||
- mix git_ops.project_info -f dotenv > project_info.env
|
||||
artifacts:
|
||||
paths:
|
||||
- _build/
|
||||
- deps/
|
||||
- .hex
|
||||
- .mix
|
||||
reports:
|
||||
dotenv: project_info.env
|
||||
|
||||
test:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: test
|
||||
script:
|
||||
- mix test
|
||||
|
||||
credo:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: test
|
||||
script:
|
||||
- mix credo
|
||||
|
||||
audit:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: test
|
||||
script:
|
||||
- mix hex.audit
|
||||
|
||||
format:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: test
|
||||
script:
|
||||
- mix format --check-formatted
|
||||
|
||||
pages:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: release
|
||||
script:
|
||||
- mix docs -o public
|
||||
artifacts:
|
||||
paths:
|
||||
- public
|
||||
only:
|
||||
- main
|
||||
|
||||
git_ops:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: release
|
||||
only:
|
||||
refs:
|
||||
- main
|
||||
except:
|
||||
variables:
|
||||
- $CI_COMMIT_MESSAGE =~ /chore\:\ release version/
|
||||
script:
|
||||
- |
|
||||
export OLD_APP_VERSION=$APP_VERSION
|
||||
mkdir -p artifacts
|
||||
git config --global user.name "Gitlab Runner for ${GITLAB_USER_NAME}"
|
||||
git config --global user.email "${GITLAB_USER_EMAIL}"
|
||||
mix git_ops.release --yes || true
|
||||
mix git_ops.project_info -f shell > artifacts/env
|
||||
source artifacts/env
|
||||
if [ "v${OLD_APP_VERSION}" != "v${APP_VERSION}" ]; then
|
||||
mix hex.build -o "artifacts/${APP_NAME}-${APP_VERSION}.tar"
|
||||
gzip "artifacts/${APP_NAME}-${APP_VERSION}.tar"
|
||||
mix docs && tar zcvf "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" doc/
|
||||
curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz"
|
||||
curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz"
|
||||
git push "https://project_${CI_PROJECT_ID}_bot:${RELEASE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git" "HEAD:${CI_COMMIT_REF_NAME}" "refs/tags/v${APP_VERSION}"
|
||||
fi
|
||||
artifacts:
|
||||
paths:
|
||||
- artifacts/*
|
||||
|
||||
release-gitlab:
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: release
|
||||
only:
|
||||
- tags
|
||||
- /^v\d+\.\d+\.\d+(-\w+)?$/
|
||||
script:
|
||||
- release-cli create \
|
||||
--name "Release ${APP_NAME} ${APP_VERSION}" \
|
||||
--description "./CHANGELOG.md" \
|
||||
--tag-name "v${APP_VERSION}" \
|
||||
--assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz\"}" \
|
||||
--assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}-docs.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz\"}"
|
||||
|
||||
release-hex:
|
||||
image: elixir:latest
|
||||
dependencies:
|
||||
- build
|
||||
stage: release
|
||||
only:
|
||||
- tags
|
||||
- /^v\d+\.\d+\.\d+(-\w+)?$/
|
||||
script:
|
||||
- mix hex.publish --yes
|
2
.tool-versions
Normal file
2
.tool-versions
Normal file
|
@ -0,0 +1,2 @@
|
|||
erlang 26.2.2
|
||||
elixir 1.16.1
|
47
CHANGELOG.md
47
CHANGELOG.md
|
@ -5,59 +5,40 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
|
|||
|
||||
<!-- changelog -->
|
||||
|
||||
## [v2.0.1](https://gitlab.com/jimsy/ip/compare/v2.0.0...v2.0.1) (2023-10-03)
|
||||
|
||||
|
||||
|
||||
## [v2.0.1](https://harton.dev/james/ip/compare/v2.0.0...v2.0.1) (2023-10-03)
|
||||
|
||||
### Improvements:
|
||||
|
||||
* Add `IP.Address.to_tuple/1`.
|
||||
- Add `IP.Address.to_tuple/1`.
|
||||
|
||||
## [v2.0.0](https://harton.dev/james/ip/compare/v1.2.3...v2.0.0) (2023-01-16)
|
||||
|
||||
## [v2.0.0](https://gitlab.com/jimsy/ip/compare/v1.2.3...v2.0.0) (2023-01-16)
|
||||
### Breaking Changes:
|
||||
|
||||
* Relicense to HL3-FULL.
|
||||
|
||||
|
||||
|
||||
## [v1.2.3](https://gitlab.com/jimsy/ip/compare/v1.2.2...v1.2.3) (2022-10-03)
|
||||
|
||||
|
||||
- Relicense to HL3-FULL.
|
||||
|
||||
## [v1.2.3](https://harton.dev/james/ip/compare/v1.2.2...v1.2.3) (2022-10-03)
|
||||
|
||||
### Improvements:
|
||||
|
||||
* Add :crypto to extra_applications
|
||||
|
||||
## [v1.2.2](https://gitlab.com/jimsy/ip/compare/v1.2.1...v1.2.2) (2022-09-27)
|
||||
|
||||
|
||||
- Add :crypto to extra_applications
|
||||
|
||||
## [v1.2.2](https://harton.dev/james/ip/compare/v1.2.1...v1.2.2) (2022-09-27)
|
||||
|
||||
### Improvements:
|
||||
|
||||
* Update Bitwise use, libs
|
||||
|
||||
## [v1.2.1](https://gitlab.com/jimsy/ip/compare/v1.2.0...v1.2.1) (2022-09-22)
|
||||
|
||||
|
||||
- Update Bitwise use, libs
|
||||
|
||||
## [v1.2.1](https://harton.dev/james/ip/compare/v1.2.0...v1.2.1) (2022-09-22)
|
||||
|
||||
### Bug Fixes:
|
||||
|
||||
* correctly validate IPv4 netmasks
|
||||
|
||||
## [v1.2.0](https://gitlab.com/jimsy/ip/compare/v1.1.1...v1.2.0) (2022-03-01)
|
||||
|
||||
|
||||
- correctly validate IPv4 netmasks
|
||||
|
||||
## [v1.2.0](https://harton.dev/james/ip/compare/v1.1.1...v1.2.0) (2022-03-01)
|
||||
|
||||
### Features:
|
||||
|
||||
* add `Address.from_tuple/1` and `Address.from_tuple!/1`
|
||||
|
||||
## [v1.1.1](https://gitlab.com/jimsy/ip/compare/v1.1.1...v1.1.1) (2021-12-08)
|
||||
|
||||
|
||||
- add `Address.from_tuple/1` and `Address.from_tuple!/1`
|
||||
|
||||
## [v1.1.1](https://harton.dev/james/ip/compare/v1.1.1...v1.1.1) (2021-12-08)
|
||||
|
|
10
README.md
10
README.md
|
@ -1,6 +1,6 @@
|
|||
# IP
|
||||
|
||||
[![pipeline status](https://gitlab.com/jimsy/ip/badges/main/pipeline.svg)](https://gitlab.com/jimsy/ip/commits/main)
|
||||
[![Build Status](https://drone.harton.dev/api/badges/james/ip/status.svg)](https://drone.harton.dev/james/ip)
|
||||
[![Hex.pm](https://img.shields.io/hexpm/v/ip.svg)](https://hex.pm/packages/ip)
|
||||
[![Hippocratic License HL3-FULL](https://img.shields.io/static/v1?label=Hippocratic%20License&message=HL3-FULL&labelColor=5e2751&color=bc8c3d)](https://firstdonoharm.dev/version/3/0/full.html)
|
||||
|
||||
|
@ -38,6 +38,12 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
|
|||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at [https://hexdocs.pm/ip](https://hexdocs.pm/ip).
|
||||
|
||||
## Github Mirror
|
||||
|
||||
This repository is mirrored [on Github](https://github.com/jimsynz/ip)
|
||||
from it's primary location [on my Forejo instance](https://harton.dev/james/ip).
|
||||
Feel free to raise issues and open PRs on Github.
|
||||
|
||||
## License
|
||||
|
||||
This software is licensed under the terms of the
|
||||
|
@ -45,7 +51,7 @@ This software is licensed under the terms of the
|
|||
this package for the terms.
|
||||
|
||||
This license actively proscribes this software being used by and for some
|
||||
industries, countries and activities. If your usage of this software doesn't
|
||||
industries, countries and activities. If your usage of this software doesn't
|
||||
comply with the terms of this license, then [contact me](mailto:james@harton.nz)
|
||||
with the details of your use-case to organise the purchase of a license - the
|
||||
cost of which may include a donation to a suitable charity or NGO.
|
||||
|
|
|
@ -3,7 +3,7 @@ import Config
|
|||
config :git_ops,
|
||||
mix_project: Mix.Project.get!(),
|
||||
changelog_file: "CHANGELOG.md",
|
||||
repository_url: "https://gitlab.com/jimsy/ip",
|
||||
repository_url: "https://harton.dev/james/ip",
|
||||
manage_mix_version?: true,
|
||||
manage_readme_version: "README.md",
|
||||
version_tag_prefix: "v"
|
||||
|
|
|
@ -45,10 +45,6 @@ defimpl Enumerable, for: IP.Prefix do
|
|||
["192.0.2.128", "192.0.2.130", "192.0.2.132", "192.0.2.134"]
|
||||
"""
|
||||
@spec reduce(Prefix.t(), Enumerable.acc(), Enumerable.reducer()) :: Enumerable.result()
|
||||
def reduce(_, {:halt, acc}, _fun), do: {:halted, acc}
|
||||
|
||||
def reduce({prefix, pos, last}, {:suspend, acc}, fun),
|
||||
do: {:suspended, acc, &reduce({prefix, pos, last}, &1, fun)}
|
||||
|
||||
def reduce(%Prefix{} = prefix, {:cont, acc}, fun) do
|
||||
first =
|
||||
|
@ -61,21 +57,26 @@ defimpl Enumerable, for: IP.Prefix do
|
|||
|> Prefix.last()
|
||||
|> Address.to_integer()
|
||||
|
||||
reduce({prefix, first, last}, {:cont, acc}, fun)
|
||||
do_reduce({prefix, first, last}, {:cont, acc}, fun)
|
||||
end
|
||||
|
||||
def reduce(
|
||||
{%Prefix{address: %Address{version: version}} = prefix, pos, last},
|
||||
{:cont, acc},
|
||||
fun
|
||||
) do
|
||||
defp do_reduce(_, {:halt, acc}, _fun), do: {:halted, acc}
|
||||
|
||||
defp do_reduce({prefix, pos, last}, {:suspend, acc}, fun),
|
||||
do: {:suspended, acc, &do_reduce({prefix, pos, last}, &1, fun)}
|
||||
|
||||
defp do_reduce(
|
||||
{%Prefix{address: %Address{version: version}} = prefix, pos, last},
|
||||
{:cont, acc},
|
||||
fun
|
||||
) do
|
||||
case pos do
|
||||
^last ->
|
||||
{:done, acc}
|
||||
|
||||
pos ->
|
||||
next = Address.from_integer!(pos, version)
|
||||
reduce({prefix, pos + 1, last}, fun.(next, acc), fun)
|
||||
do_reduce({prefix, pos + 1, last}, fun.(next, acc), fun)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ defimpl Inspect, for: IP.Address do
|
|||
iex> ~i(2001:db8::1)
|
||||
#IP.Address<2001:db8::1 DOCUMENTATION>
|
||||
"""
|
||||
@spec inspect(Address.t(), list) :: binary
|
||||
@spec inspect(Address.t(), Inspect.Opts.t()) :: Inspect.Algebra.t()
|
||||
def inspect(address, _opts) do
|
||||
scope = Scope.address_scope(address)
|
||||
concat(["#IP.Address<#{address} #{scope}>"])
|
||||
|
|
|
@ -15,7 +15,7 @@ defimpl Inspect, for: IP.Prefix do
|
|||
...> |> IP.Address.to_prefix(32)
|
||||
#IP.Prefix<192.0.2.1/32 DOCUMENTATION>
|
||||
"""
|
||||
@spec inspect(Prefix.t(), list) :: binary
|
||||
@spec inspect(Prefix.t(), Inspect.Opts.t()) :: Inspect.Algebra.t()
|
||||
def inspect(%Prefix{} = prefix, _opts) do
|
||||
scope = Scope.prefix_scope(prefix)
|
||||
concat(["#IP.Prefix<#{prefix} #{scope}>"])
|
||||
|
|
|
@ -34,13 +34,13 @@ defmodule IP.Prefix.EUI64 do
|
|||
{:ok, head, tail}
|
||||
end
|
||||
|
||||
def generate_eui(head, tail) do
|
||||
defp generate_eui(head, tail) do
|
||||
address = (head <<< 40) + (0xFFFE <<< 24) + tail
|
||||
address = Bitwise.bxor(address, 0x0200000000000000)
|
||||
{:ok, address}
|
||||
end
|
||||
|
||||
def hex_to_int(mac) do
|
||||
defp hex_to_int(mac) do
|
||||
{:ok, String.to_integer(mac, 16)}
|
||||
rescue
|
||||
ArgumentError -> {:error, "Unable to parse MAC address"}
|
||||
|
|
9
mix.exs
9
mix.exs
|
@ -23,7 +23,7 @@ defmodule IP.Mixfile do
|
|||
maintainers: ["James Harton <james@harton.nz>"],
|
||||
licenses: ["HL3-FULL"],
|
||||
links: %{
|
||||
"Source" => "https://gitlab.com/jimsy/ip"
|
||||
"Source" => "https://harton.dev/james/ip"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
@ -39,8 +39,11 @@ defmodule IP.Mixfile do
|
|||
defp deps do
|
||||
[
|
||||
{:credo, "~> 1.6", only: ~w[dev test]a, runtime: false},
|
||||
{:earmark, "~> 1.4", only: ~w[dev test]a},
|
||||
{:ex_doc, "~> 0.30", only: ~w[dev test]a},
|
||||
{:dialyxir, "~> 1.4", only: ~w[dev test]a, runtime: false},
|
||||
{:doctor, "~> 0.21", only: ~w[dev test]a, runtime: false},
|
||||
{:ex_check, "~> 0.15.0", only: ~w[dev test]a, runtime: false},
|
||||
{:ex_doc, "~> 0.30", only: ~w[dev test]a, runtime: false},
|
||||
{:earmark, "~> 1.4", only: ~w[dev test]a, runtime: false},
|
||||
{:git_ops, "~> 2.4", only: ~w[dev test]a, runtime: false}
|
||||
]
|
||||
end
|
||||
|
|
6
mix.lock
6
mix.lock
|
@ -1,18 +1,20 @@
|
|||
%{
|
||||
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
|
||||
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
|
||||
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
|
||||
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
|
||||
"doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"},
|
||||
"earmark": {:hex, :earmark, "1.4.27", "b413b0379043df51475a9b22ce344e8a58a117516c735b8871e6cdd5ed0f0153", [:mix], [{:earmark_parser, "~> 1.4.26", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "579ebe2eaf4c7e040815a73a268036bcd96e6aab8ad2b1fcd979aaeb1ea47e15"},
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"},
|
||||
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
|
||||
"ex_check": {:hex, :ex_check, "0.15.0", "074b94c02de11c37bba1ca82ae5cc4926e6ccee862e57a485b6ba60fca2d8dc1", [:mix], [], "hexpm", "33848031a0c7e4209c3b4369ce154019788b5219956220c35ca5474299fb6a0e"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.30.0", "ed94bf5183f559d2f825e4f866cc0eab277bbb17da76aff40f8e0f149656943e", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "6743fe46704fe27e2f2558faa61f00e5356528768807badb2092d38476d6dac2"},
|
||||
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
|
||||
"git_ops": {:hex, :git_ops, "2.4.5", "185a724dfde3745edd22f7571d59c47a835cf54ded67e9ccbc951920b7eec4c2", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e323a5b01ad53bc8c19c3a444be3e61ed7803ecd2e95530446ae9327d0143ecc"},
|
||||
"inch_ex": {:hex, :inch_ex, "1.0.0", "18496a900ca4b7542a1ff1159e7f8be6c2012b74ca55ac70de5e805f14cdf939", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
|
||||
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
|
||||
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
|
||||
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ defmodule EnumerableIPPrefixTest do
|
|||
import IP.Sigil
|
||||
doctest Enumerable.IP.Prefix
|
||||
|
||||
# Regression: https://gitlab.com/jimsy/ip/issues/1
|
||||
# Regression: https://harton.dev/james/ip/issues/1
|
||||
test "correctly returns the first address in the range" do
|
||||
assert Enum.take(~i(10.10.10.0/24), 1) == [~i(10.10.10.0)]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue