From afa22e1695fabdcbd3e270604ddba09bd28aab28 Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Wed, 22 Nov 2023 19:17:33 +0100 Subject: [PATCH] ci: add test & release workflows --- .github/workflows/release.yml | 72 +++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..56bafee --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Release + +on: + push: + branches: + - main + - dev + +permissions: + contents: read + +jobs: + test: + uses: ./.github/workflows/test.yml + permissions: + contents: read + + release: + needs: test + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + persist-credentials: false + + - name: Use Node.js LTS + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4 + with: + node-version-file: ".tool-versions" + + - name: Install packages + run: npm ci + + - name: Audit npm signatures + run: npm audit signatures + + - name: Run Semantic Release + run: npx semantic-release + env: + GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} + + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + version-type: strict + version-file: .tool-versions + + - name: Restore dependencies cache + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + env: + cache-name: mix-deps + with: + path: deps + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + + - name: Restore build cache + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + env: + cache-name: mix-build + with: + path: _build + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + + - name: Publish to Hex + run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7d4769b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,75 @@ +name: Test + +on: + push: + # ignore branches where the release workflow runs as it already calls this one + branches-ignore: + - main + - dev + pull_request: + workflow_call: + +permissions: + contents: read + +env: + MIX_ENV: test + +jobs: + # ignore the push event trigger if a PR is open for the current branch + prevent-duplicate-checks: + runs-on: ubuntu-latest + steps: + - uses: insurgent-lab/is-in-pr-action@78ecb5daf15aca198aeb2b6f208aabd06b2cb716 # v0.1.4 + id: isInPR + outputs: + should-run: ${{ !(steps.isInPR.outputs.result == 'true' && github.event_name == 'push') }} + + test: + name: Build and test + + runs-on: ubuntu-latest + timeout-minutes: 5 + + needs: prevent-duplicate-checks + if: ${{ needs.prevent-duplicate-checks.outputs.should-run == 'true' }} + + steps: + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + version-type: strict + version-file: .tool-versions + + - name: Restore dependencies cache + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + env: + cache-name: mix-deps + with: + path: deps + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + + - name: Restore build cache + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + env: + cache-name: mix-build + with: + path: _build + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + + - name: Install dependencies + run: mix deps.get + + - name: Check formatting + run: mix format --check-formatted + + - name: Compile code (without warning) and deps + run: mix compile --warnings-as-errors + + - name: Run tests + run: mix test