Skip to content

Commit

Permalink
Initial GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Mar 29, 2019
1 parent 565343f commit dddf5a1
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/actions/changelog/Dockerfile
@@ -0,0 +1,6 @@
FROM ruby:2

WORKDIR /github/workspace
COPY ./entrypoint.rb /entrypoint.rb
RUN chmod +x /entrypoint.rb
ENTRYPOINT [ "/entrypoint.rb" ]
21 changes: 21 additions & 0 deletions .github/actions/changelog/entrypoint.rb
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby

version = (ENV['REF'] || ENV['GITHUB_REF'] || '').sub(%r{\Arefs/tags/v}, '')
log = File.read(ENV['CHANGELOG'] || Dir.glob('CHANGELOG*').first)
rlsfile = ENV['RELEASE_FILE'] || '/github/home/.releasenotes'

match = /^#\s*\[#{version}\]\s+-\s+(?<title>.+?)\r?\n(?<body>.*?)\r?\n#/ms.match(log)
unless match
puts "No Changelog notes found for v#{version}"
exit 78
end

title = "Release: v#{version} (#{match.named_captures['title'].strip})"
body = match.named_captures['body'].strip
notes = "#{title}\n\n#{body}"

puts "Release Notes for v#{version}:"
puts ""
puts notes

File.open(rlsfile, 'w') {|f| f.write(notes) }
3 changes: 3 additions & 0 deletions .github/actions/install/Dockerfile
@@ -0,0 +1,3 @@
FROM ruby:2
ENV BUNDLE_PATH=/github/home/.bundle
ENTRYPOINT sh -c "bundle install"
3 changes: 3 additions & 0 deletions .github/actions/package/Dockerfile
@@ -0,0 +1,3 @@
FROM ruby:2
ENV BUNDLE_PATH=/github/home/.bundle
ENTRYPOINT sh -c "bundle exec rake gem && bundle exec rake install"
16 changes: 16 additions & 0 deletions .github/actions/release/Dockerfile
@@ -0,0 +1,16 @@
FROM alpine:latest

LABEL "com.github.actions.name"="GitHub Release"
LABEL "com.github.actions.description"="Create a GitHub release"
LABEL "com.github.actions.icon"="command"
LABEL "com.github.actions.color"="blue"
LABEL "maintainer"="Loren Segal <lsegal@soen.ca>"

RUN apk add --no-cache -U \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
hub git

WORKDIR /github/workspace
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
6 changes: 6 additions & 0 deletions .github/actions/release/entrypoint.sh
@@ -0,0 +1,6 @@
#!/bin/sh

export GITHUB_TOKEN=${RELEASE_TOKEN:-$GITHUB_TOKEN}
export TAG=${GITHUB_REF#refs/tags/}

hub release create -a $ARTIFACT -F ${RELEASE_FILE:-/github/home/.releasenotes} $TAG
3 changes: 3 additions & 0 deletions .github/actions/test/Dockerfile
@@ -0,0 +1,3 @@
FROM ruby:2
ENV BUNDLE_PATH=/github/home/.bundle
ENTRYPOINT sh -c "bundle exec rake"
42 changes: 42 additions & 0 deletions .github/main.workflow
@@ -0,0 +1,42 @@
workflow "Build, Test, and Publish" {
on = "push"
resolves = ["Package Gem", "Publish Gem", "Create GitHub Release"]
}

action "Install" {
uses = "./.github/actions/install"
}

action "Test" {
needs = "Install"
uses = "./.github/actions/test"
}

action "Package Gem" {
needs = "Test"
uses = "./.github/actions/package"
}

action "On Tag" {
needs = "Package Gem"
uses = "actions/bin/filter@master"
args = "tag v*"
}

action "Release Notes" {
needs = "On Tag"
uses = "./.github/actions/changelog"
}

action "Create GitHub Release" {
needs = "Release Notes"
uses = "./.github/actions/release"
secrets = ["RELEASE_TOKEN"]
}

action "Publish Gem" {
needs = "On Tag"
uses = "scarhand/actions-ruby@master"
args = "push *.gem"
secrets = ["RUBYGEMS_AUTH_TOKEN"]
}

0 comments on commit dddf5a1

Please sign in to comment.