revelrylabs / text_chunker_ex

A library for semantically coherent text chunking
MIT License
66 stars 4 forks source link

Engineer - CI Deployment - Conditional Mix Publishing #4

Closed stuartjohnpage closed 6 months ago

stuartjohnpage commented 7 months ago

Background

Optimize the continuous integration workflow for the Text Chunker open-source project to trigger package publishing only when a release is tagged.

Acceptance Criteria

Scenario: Publishing package only on release tag

stuartjohnpage commented 7 months ago

Given the existing CI configuration file, we need to make adjustments so that the 'Deploy package' step is only triggered when a release is tagged, not on every push to main. We also need to ensure that the release tags follow a pattern.

The updated GitHub Actions configuration file might look like this:

name: Test
on:
  push:
    branches:
      - main
    tags:
      - 'v*.*.*' # This pattern triggers the workflow for tags like v1.0.0, v1.2.3, etc.

permissions:
  contents: read

jobs:
  build:
    name: test and deploy
    runs-on: ubuntu-22.04
    env:
      HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
      MIX_ENV: test
    strategy:
      matrix:
        otp: ["25.2"]
        elixir: ["1.15.6"]
    steps:
      - uses: actions/checkout@v3
      - uses: erlef/setup-beam@v1
        with:
          otp-version: ${{matrix.otp}}
          elixir-version: ${{matrix.elixir}}
      - name: Restore dependencies cache
        uses: actions/cache@v3
        with:
          path: deps
          key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
          restore-keys: ${{ runner.os }}-mix-
      - name: Install dependencies
        run: mix deps.get
      - name: Run tests
        run: mix test
      - name: Deploy package
        if: startsWith(github.ref, 'refs/tags/v') # Condition to check if it's a valid version tag
        run: mix hex.publish --yes

Here's what changed:

  1. Added a tags trigger in the on section, specifying that it should match tags like "v1.0.0", "v1.2.3", and so on, ('v*.*.*'). This assumes your versioning follows the semantic versioning pattern with a 'v' prefix.

  2. Modified the if condition in the 'Deploy package' step to evaluate whether the Git reference starts with refs/tags/v. This ensures that publishing only occurs when a tag is pushed that matches the version pattern.

Make sure to replace the tag pattern 'v*.*.*' according to your project's tagging conventions.

created by stuart.page@revelry.co using Prodops

stuartjohnpage commented 6 months ago

This has been achieved!