|
| 1 | +name: Elixir CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + MIX_ENV: test |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Restore file modification timestamps |
| 27 | + uses: chetan/git-restore-mtime-action@v2 |
| 28 | + |
| 29 | + - name: Build the Docker image |
| 30 | + run: | |
| 31 | + docker login -u ${{ github.actor }} -p ${{ github.token }} ghcr.io |
| 32 | +
|
| 33 | + image="ghcr.io/${{ github.repository }}" |
| 34 | + sha_tag="${image}:${{ github.sha }}" |
| 35 | + branch="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" |
| 36 | + branch_tag="${image}:${branch}" |
| 37 | +
|
| 38 | + builder_tag="${branch_tag}_builder" |
| 39 | + main_builder_tag="${image}:main_builder" |
| 40 | +
|
| 41 | + main_tag="${image}:main" |
| 42 | +
|
| 43 | + docker buildx build --push --tag $builder_tag \ |
| 44 | + --target builder \ |
| 45 | + --cache-to type=inline \ |
| 46 | + --cache-from $main_builder_tag \ |
| 47 | + --cache-from $builder_tag \ |
| 48 | + . |
| 49 | +
|
| 50 | + docker buildx build --push --tag $branch_tag --tag $sha_tag \ |
| 51 | + --target runner \ |
| 52 | + --cache-to type=inline \ |
| 53 | + --cache-from $builder_tag \ |
| 54 | + --cache-from $main_tag \ |
| 55 | + --cache-from $branch_tag \ |
| 56 | + . |
| 57 | +
|
| 58 | + build_devcontainer: |
| 59 | + name: Build devcontainer |
| 60 | + runs-on: ubuntu-latest |
| 61 | + outputs: |
| 62 | + image: ${{ steps.build_docker_image.outputs.image }} |
| 63 | + steps: |
| 64 | + - name: Checkout code |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + fetch-depth: 0 |
| 68 | + |
| 69 | + - name: Restore file modification timestamps |
| 70 | + uses: chetan/git-restore-mtime-action@v2 |
| 71 | + |
| 72 | + - id: build_docker_image |
| 73 | + name: Build the Docker image |
| 74 | + run: | |
| 75 | + docker login -u ${{ github.actor }} -p ${{ github.token }} ghcr.io |
| 76 | +
|
| 77 | + image="ghcr.io/${{ github.repository }}" |
| 78 | + sha_tag="${image}:${{ github.sha }}" |
| 79 | + branch="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" |
| 80 | + branch_tag="${image}:${branch}" |
| 81 | +
|
| 82 | + devcontainer_tag="${branch_tag}_devcontainer" |
| 83 | + main_devcontainer_tag="${image}:main_devcontainer" |
| 84 | +
|
| 85 | + docker buildx build --push --tag $devcontainer_tag \ |
| 86 | + --target devcontainer \ |
| 87 | + --build-arg USER_UID=1001 \ |
| 88 | + --cache-to type=inline \ |
| 89 | + --cache-from $main_devcontainer_tag \ |
| 90 | + --cache-from $devcontainer_tag \ |
| 91 | + . |
| 92 | +
|
| 93 | + echo "image=${devcontainer_tag}" >> "$GITHUB_OUTPUT" |
| 94 | +
|
| 95 | + test: |
| 96 | + name: Test |
| 97 | + runs-on: ubuntu-latest |
| 98 | + needs: build_devcontainer |
| 99 | + container: |
| 100 | + image: ${{ needs.build_devcontainer.outputs.image }} |
| 101 | + credentials: |
| 102 | + username: ${{ github.actor }} |
| 103 | + password: ${{ github.token }} |
| 104 | + options: --user 1001 |
| 105 | + steps: |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
| 110 | + |
| 111 | + - name: Restore file modification timestamps |
| 112 | + uses: chetan/git-restore-mtime-action@v2 |
| 113 | + |
| 114 | + - name: Cache deps |
| 115 | + id: cache-deps |
| 116 | + uses: actions/cache@v4 |
| 117 | + env: |
| 118 | + cache-name: cache-elixir-deps |
| 119 | + with: |
| 120 | + path: deps |
| 121 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 122 | + restore-keys: | |
| 123 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 124 | +
|
| 125 | + - name: Cache compiled build |
| 126 | + id: cache-build |
| 127 | + uses: actions/cache@v4 |
| 128 | + env: |
| 129 | + cache-name: cache-compiled-build |
| 130 | + with: |
| 131 | + path: _build |
| 132 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 133 | + restore-keys: | |
| 134 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 135 | + ${{ runner.os }}-mix- |
| 136 | +
|
| 137 | + - name: Clean to rule out incremental build as a source of flakiness |
| 138 | + if: github.run_attempt != '1' |
| 139 | + run: | |
| 140 | + mix deps.clean --all |
| 141 | + mix clean |
| 142 | + shell: sh |
| 143 | + |
| 144 | + - name: Install dependencies |
| 145 | + run: mix deps.get |
| 146 | + |
| 147 | + - name: Compiles without warnings |
| 148 | + run: mix compile --warnings-as-errors |
| 149 | + |
| 150 | + - name: Check Formatting |
| 151 | + run: mix format --check-formatted |
| 152 | + |
| 153 | + - name: Check for retired dependencies |
| 154 | + run: mix hex.audit |
| 155 | + |
| 156 | + - name: Check for unused dependencies |
| 157 | + run: mix deps.unlock --check-unused |
| 158 | + |
| 159 | + - name: Run tests |
| 160 | + run: mix test |
0 commit comments