Skip to content

Commit

Permalink
Replace Travis with Github Workflows
Browse files Browse the repository at this point in the history
[changelog]
added: coverage check
changed: min version now 1.6
changed: replace Travis with Github CI workflow
changed: add Github release workflow
changed: updated CI badge in README
changed: moduledoc for main module to pull from README
changed: MIT licence replaced with Apache 2.0 licence
fixed: formatting
  • Loading branch information
OldhamMade committed Jun 18, 2021
1 parent 195fcfd commit 152790d
Show file tree
Hide file tree
Showing 12 changed files with 566 additions and 150 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Changelog Check

on:
# Trigger this workflow on push (merge) events,
# but ignore the main branch
push:
branches-ignore:
- main

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
changelog:
runs-on: ubuntu-latest

steps:
- name: "[Git] Checkout code"
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: "[Setup] Open /usr/local/bin Permissions"
run: sudo chmod -R a+rwx /usr/local/bin

- name: "[Setup] Cache Dependencies"
id: cache
uses: actions/cache@v2
with:
path: |
/usr/local/bin/git-cl
key: ${{ runner.os }}-release
restore-keys: |
${{ runner.os }}-release
- name: "[Changelog] Install build tools"
uses: fwal/setup-swift@v1
if: steps.cache.outputs.cache-hit != 'true'
with:
swift-version: "5.2"

- name: "[Changelog] Install git-ci"
if: steps.cache.outputs.cache-hit != 'true'
run: |
cd /tmp/
git clone https://github.com/uptech/git-cl.git git-cl
cd ./git-cl
make -j$(nproc)
sudo make install
sudo chmod a+rwx /usr/local/bin/git-cl
cd ${GITHUB_WORKSPACE}
- name: "[Changelog] Fail if no changelog entries"
run: |
# echo output for debugging
git cl unreleased | tail -n +4 | xargs
# test output and fail step if empty
[ "$(git cl unreleased | tail -n +4 | xargs)" ] || exit 1
166 changes: 166 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: CI

on: push

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- elixir: 1.6
otp: 20.3
- elixir: 1.7.x
otp: 21.x
- elixir: 1.8.x
otp: 21.x
- elixir: 1.9.x
otp: 22.x
- elixir: 1.10.x
otp: 23.x
- elixir: 1.11.x
otp: 23.x
- elixir: 1.12.x
otp: 24.x

steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}}
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
deps
_build/test/lib
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
- name: Install Dependencies
run: mix deps.get

- name: Build Dependencies
env:
MIX_ENV: test
run: mix deps.compile

- name: Build Project
env:
MIX_ENV: test
run: mix compile --warnings-as-errors

lint:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: '1.11.x'
otp-version: '23.2.1'
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
deps
_build/test/lib
key: ${{ runner.os }}-mix-test-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-test-
- name: Check formatting
env:
MIX_ENV: test
run: mix format --check-formatted

test:
runs-on: ubuntu-latest
needs: build

strategy:
matrix:
include:
- elixir: 1.6
otp: 20.3
- elixir: 1.7.x
otp: 21.x
- elixir: 1.8.x
otp: 21.x
- elixir: 1.9.x
otp: 22.x
- elixir: 1.10.x
otp: 23.x
- elixir: 1.11.x
otp: 23.x

steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}}
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
deps
_build/test/lib
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
- name: Run tests
run: mix test

coverage:
runs-on: ubuntu-latest
needs: test

strategy:
matrix:
include:
- elixir: 1.6
otp: 20.3
- elixir: 1.7.x
otp: 21.x
- elixir: 1.8.x
otp: 21.x
- elixir: 1.9.x
otp: 22.x
- elixir: 1.10.x
otp: 23.x
- elixir: 1.11.x
otp: 23.x

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}}
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
deps
_build/test/lib
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
- name: Build ExCoveralls
run: mix compile excoveralls

- name: Coverage Summary
run: mix coveralls

- name: Publish Coverage
run: mix coveralls.github
138 changes: 138 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Release

on:
# Trigger this workflow on push (merge) events,
# but only for the main branch
push:
branches:
- main

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSIONS_OTP: '24.0.1'
VERSIONS_ELIXIR: '1.12.x'
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}

jobs:
release:
name: Create Release
runs-on: ubuntu-latest

steps:
- name: "[Git] Checkout code"
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: "[Git] Capture message"
run: |
# Actions do not support multiline `::set-output`s
echo 'COMMIT_MSG<<EOM' >> "$GITHUB_ENV"
git log -n1 --pretty='%B' >> "$GITHUB_ENV"
echo 'EOM' >> "$GITHUB_ENV"
- name: "[Setup] Open /usr/local/bin Permissions"
run: sudo chmod -R a+rwx /usr/local/bin

- name: "[Setup] Cache Dependencies"
id: cache
uses: actions/cache@v2
with:
path: |
deps
_build/test/lib
/usr/local/bin/git-cl
key: ${{ runner.os }}-release
restore-keys: |
${{ runner.os }}-release
- name: "[Setup] Setup Elixir"
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ env.VERSIONS_ELIXIR }}
otp-version: ${{ env.VERSIONS_OTP }}

- name: "[Version] Install"
uses: gittools/actions/gitversion/setup@v0.9.6
with:
versionSpec: '5.x'

- name: "[Version] Calculate"
id: gitversion # step id used as reference for output values
uses: gittools/actions/gitversion/execute@v0.9.6

- name: "[Version] Capture"
run: echo "RELEASE_VERSION=${{ steps.gitversion.outputs.semVer }}" >> $GITHUB_ENV

- name: "[Version] Update"
run: |
sed -i 's/@version ".*"/@version "${{env.RELEASE_VERSION}}"/gi' mix.exs
- name: "[Changelog] Install build tools"
uses: fwal/setup-swift@v1
if: steps.cache.outputs.cache-hit != 'true'
with:
swift-version: "5.2"

- name: "[Changelog] Install git-ci"
if: steps.cache.outputs.cache-hit != 'true'
run: |
cd /tmp/
git clone https://github.com/uptech/git-cl.git git-cl
cd ./git-cl
make -j$(nproc)
sudo make install
sudo chmod a+rwx /usr/local/bin/git-cl
cd ${GITHUB_WORKSPACE}
- name: "[Changelog] Fail if no changelog entries"
run: |
# echo output for debugging
git cl unreleased | tail -n +4 | xargs
# test output and fail step if empty
[ "$(git cl unreleased | tail -n +4 | xargs)" ] || exit 1
- name: "[Changelog] Generate"
run: |
git cl full > CHANGELOG.md
TODAY=$(date '+%Y-%m-%d')
sed -i "s/^## \[Unreleased\] - now/## [${{env.RELEASE_VERSION}}] - ${TODAY}/" CHANGELOG.md
sed -i "7,8d" CHANGELOG.md
- name: "[Release] Commit release updates"
uses: stefanzweifel/git-auto-commit-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# --amend --no-edit doesn't work because of default --message
# (effectively --no-edit is ignored)
commit_message: ${{ env.COMMIT_MSG }}
commit_options: --amend --no-edit
push_options: --force
# so as not to make too shallow for commit --amend and push -f
skip_fetch: true

- name: "[Release] Create new release"
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{env.RELEASE_VERSION}}
release_name: ${{env.RELEASE_VERSION}}
body: |
Please see the CHANGELOG for further details
draft: false
prerelease: false

- name: "[Release] Setup Elixir for Publishing to Hex.pm"
uses: erlef/setup-elixir@v1
with:
elixir-version: 1.11.x
otp-version: 23.x

- name: "[Release] Publish to Hex.pm"
run: |
mix local.hex --force
mix local.rebar --force
mix do deps.get, deps.compile
mix hex.build
mix hex.publish --yes
Loading

0 comments on commit 152790d

Please sign in to comment.