Skip to content

Commit

Permalink
Automate publish on version changes (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Apr 28, 2023
1 parent 0186f51 commit f107901
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/outdated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: 24.0
elixir-version: 1.12.2
otp-version: 25.3
elixir-version: 1.14.3

- name: Check outdated certdata
run: |
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

changed_version="$(git diff --name-only HEAD~1 HEAD -- VERSION)"

if [[ "${changed_version}" ]]; then
echo "Publishing because the version changed since the last commit"

git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag "v$(cat VERSION)"
git push --tags

mix hex.publish --yes
else
echo "Not publishing since the version didn't change since last commit"
fi
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish

on:
push:
branches:
- main

jobs:
publish:
name: Publish
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: 25.3
elixir-version: 1.14.3

- name: Publish
run: |
mix deps.get
mix compile
.github/workflows/publish.sh
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.1
11 changes: 8 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
defmodule CAStore.MixProject do
use Mix.Project

@version "1.0.1"
@repo_url "https://github.com/elixir-mint/castore"

def project do
[
app: :castore,
version: @version,
version: version(),
elixir: "~> 1.0",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand All @@ -20,7 +19,7 @@ defmodule CAStore.MixProject do
# Docs
name: "CAStore",
docs: [
source_ref: "v#{@version}",
source_ref: "v#{version()}",
source_url: @repo_url
]
]
Expand Down Expand Up @@ -48,4 +47,10 @@ defmodule CAStore.MixProject do
links: %{"GitHub" => @repo_url}
]
end

defp version do
"VERSION"
|> File.read!()
|> String.trim()
end
end

0 comments on commit f107901

Please sign in to comment.