|
| 1 | +on: push |
| 2 | + |
| 3 | +name: Privately published Elixir Library |
| 4 | + |
| 5 | +env: |
| 6 | + ELIXIR_VERSION: "1.9" |
| 7 | + OTP_VERSION: "22.2" |
| 8 | + |
| 9 | +jobs: |
| 10 | + deps: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + env: |
| 13 | + NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }} |
| 14 | + MIX_ENV: test |
| 15 | + steps: |
| 16 | + - name: Checking out project |
| 17 | + uses: actions/checkout@v2 |
| 18 | + - name: "Setting up Elixir" |
| 19 | + uses: actions/setup-elixir@v1 |
| 20 | + with: |
| 21 | + otp-version: ${{ env.OTP_VERSION }} |
| 22 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 23 | + - name: Signing into narrativeapp organisation on hex |
| 24 | + run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY |
| 25 | + - name: Downloading dependency cache |
| 26 | + uses: actions/cache@v2 |
| 27 | + with: |
| 28 | + path: deps |
| 29 | + key: ${{ runner.os }}-deps |
| 30 | + - run: mix deps.get |
| 31 | + - name: Uploading dependencies for other jobs |
| 32 | + uses: actions/upload-artifact@v2 |
| 33 | + with: |
| 34 | + name: deps |
| 35 | + path: deps/ |
| 36 | + |
| 37 | + build: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + needs: ["deps"] |
| 40 | + env: |
| 41 | + MIX_ENV: test |
| 42 | + steps: |
| 43 | + - name: Checking out project |
| 44 | + uses: actions/checkout@v2 |
| 45 | + - name: "Setting up Elixir" |
| 46 | + uses: actions/setup-elixir@v1 |
| 47 | + with: |
| 48 | + otp-version: ${{ env.OTP_VERSION }} |
| 49 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 50 | + - name: Downloading dependencies |
| 51 | + uses: actions/download-artifact@v2 |
| 52 | + with: |
| 53 | + name: deps |
| 54 | + path: deps/ |
| 55 | + - name: Downloading build artifact cache |
| 56 | + uses: actions/cache@v2 |
| 57 | + with: |
| 58 | + path: _build |
| 59 | + key: ${{ runner.os }}-build |
| 60 | + - name: Run `mix compile` |
| 61 | + run: mix compile |
| 62 | + - name: Uploading build artifacts for other jobs |
| 63 | + uses: actions/upload-artifact@v2 |
| 64 | + with: |
| 65 | + name: build |
| 66 | + path: _build/ |
| 67 | + |
| 68 | + credo: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: ["deps", "build"] |
| 71 | + env: |
| 72 | + MIX_ENV: test |
| 73 | + steps: |
| 74 | + - name: Checking out project |
| 75 | + uses: actions/checkout@v2 |
| 76 | + - name: "Setting up Elixir" |
| 77 | + uses: actions/setup-elixir@v1 |
| 78 | + with: |
| 79 | + otp-version: ${{ env.OTP_VERSION }} |
| 80 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 81 | + - name: Downloading dependencies |
| 82 | + uses: actions/download-artifact@v2 |
| 83 | + with: |
| 84 | + name: deps |
| 85 | + path: deps/ |
| 86 | + - name: Downloading build artifacts |
| 87 | + uses: actions/download-artifact@v2 |
| 88 | + with: |
| 89 | + name: build |
| 90 | + path: _build/ |
| 91 | + - run: mix credo --strict |
| 92 | + |
| 93 | + formatter: |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Checking out project |
| 97 | + uses: actions/checkout@v2 |
| 98 | + - name: "Setting up Elixir" |
| 99 | + uses: actions/setup-elixir@v1 |
| 100 | + with: |
| 101 | + otp-version: ${{ env.OTP_VERSION }} |
| 102 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 103 | + - run: mix format --check-formatted |
| 104 | + |
| 105 | + audit: |
| 106 | + runs-on: ubuntu-latest |
| 107 | + needs: ["deps"] |
| 108 | + env: |
| 109 | + NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }} |
| 110 | + MIX_ENV: test |
| 111 | + steps: |
| 112 | + - name: Checking out project |
| 113 | + uses: actions/checkout@v2 |
| 114 | + - name: "Setting up Elixir" |
| 115 | + uses: actions/setup-elixir@v1 |
| 116 | + with: |
| 117 | + otp-version: ${{ env.OTP_VERSION }} |
| 118 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 119 | + - run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY |
| 120 | + - name: Downloading dependencies |
| 121 | + uses: actions/download-artifact@v2 |
| 122 | + with: |
| 123 | + name: deps |
| 124 | + path: deps/ |
| 125 | + - run: mix hex.audit |
| 126 | + |
| 127 | + test: |
| 128 | + runs-on: ubuntu-latest |
| 129 | + needs: ["deps", "build"] |
| 130 | + env: |
| 131 | + MIX_ENV: test |
| 132 | + steps: |
| 133 | + - name: Checking out project |
| 134 | + uses: actions/checkout@v2 |
| 135 | + - name: "Setting up Elixir" |
| 136 | + uses: actions/setup-elixir@v1 |
| 137 | + with: |
| 138 | + otp-version: ${{ env.OTP_VERSION }} |
| 139 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 140 | + - name: Downloading dependencies |
| 141 | + uses: actions/download-artifact@v2 |
| 142 | + with: |
| 143 | + name: deps |
| 144 | + path: deps/ |
| 145 | + - name: Downloading build artifacts |
| 146 | + uses: actions/download-artifact@v2 |
| 147 | + with: |
| 148 | + name: build |
| 149 | + path: _build/ |
| 150 | + - run: mix test |
| 151 | + |
| 152 | + release: |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: ["deps", "test", "audit", "formatter", "credo"] |
| 155 | + if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }} |
| 156 | + env: |
| 157 | + HEX_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }} |
| 158 | + steps: |
| 159 | + - name: Checking out project |
| 160 | + uses: actions/checkout@v2 |
| 161 | + - name: Checking the tag version |
| 162 | + id: tag-version |
| 163 | + run: VERSION=$(basename ${{ github.ref }}) ; echo "::set-output name=tag-version::${VERSION:1}" |
| 164 | + - name: Checking the app version |
| 165 | + id: app-version |
| 166 | + run: "VERSION=$(awk -F\\\" '/version: /{print $2}' mix.exs); echo \"::set-output name=app-version::${VERSION}\"" |
| 167 | + - name: Verifying that the git tag and the version in mix.exs match |
| 168 | + run: test "xx${{ steps.tag-version.outputs.tag-version }}" = "xx${{ steps.app-version.outputs.app-version }}" |
| 169 | + - name: Checking the app name |
| 170 | + id: app-name |
| 171 | + run: 'echo "::set-output name=app-name::$(awk -F''[:,]'' ''/app: /{print $3}'' mix.exs)"' |
| 172 | + - name: "Setting up Elixir" |
| 173 | + uses: actions/setup-elixir@v1 |
| 174 | + with: |
| 175 | + otp-version: ${{ env.OTP_VERSION }} |
| 176 | + elixir-version: ${{ env.ELIXIR_VERSION }} |
| 177 | + - name: Downloading dependencies |
| 178 | + uses: actions/download-artifact@v2 |
| 179 | + with: |
| 180 | + name: deps |
| 181 | + path: deps/ |
| 182 | + - name: Downloading build artifacts |
| 183 | + uses: actions/download-artifact@v2 |
| 184 | + with: |
| 185 | + name: build |
| 186 | + path: _build/ |
| 187 | + - name: Run mix hex.build |
| 188 | + run: mix hex.build -o ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar |
| 189 | + - name: Uploading hex package as job artifact |
| 190 | + uses: actions/upload-artifact@v2 |
| 191 | + with: |
| 192 | + name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar |
| 193 | + path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar |
| 194 | + - name: Run mix docs |
| 195 | + run: MIX_ENV=test mix docs && tar zcvf docs.tar.gz doc/ |
| 196 | + - name: Uploading documentation as job artifact |
| 197 | + uses: actions/upload-artifact@v2 |
| 198 | + with: |
| 199 | + name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz |
| 200 | + path: docs.tar.gz |
| 201 | + - name: Publishing hex package |
| 202 | + run: mix hex.publish --organization narrativeapp --yes |
| 203 | + - name: Creating new Github release |
| 204 | + id: create-release |
| 205 | + uses: actions/create-release@v1 |
| 206 | + env: |
| 207 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 208 | + with: |
| 209 | + tag_name: v${{ steps.app-version.outputs.app-version }} |
| 210 | + release_name: Release ${{ steps.app-name.outputs.app-name }} ${{ steps.app-version.outputs.app-version }} |
| 211 | + body: Autogenerated from tag push |
| 212 | + - name: Uploading hex package as release artifact |
| 213 | + id: upload-package |
| 214 | + uses: actions/upload-release-asset@v1 |
| 215 | + env: |
| 216 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 217 | + with: |
| 218 | + upload_url: ${{ steps.create-release.outputs.upload_url }} |
| 219 | + asset_path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar |
| 220 | + asset_name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar |
| 221 | + asset_content_type: application/x-tar |
| 222 | + - name: Uploading documentation as release artifact |
| 223 | + id: upload-docs |
| 224 | + uses: actions/upload-release-asset@v1 |
| 225 | + env: |
| 226 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 227 | + with: |
| 228 | + upload_url: ${{ steps.create-release.outputs.upload_url }} |
| 229 | + asset_path: docs.tar.gz |
| 230 | + asset_name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz |
| 231 | + asset_content_type: application/gzip |
0 commit comments