Skip to content

Commit

Permalink
✨ Adds get-semver action container
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa committed Dec 22, 2020
1 parent bde4d50 commit 789dcbe
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Docker Image CI
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: release
on:
push:
# Use push on master event to run workflow instead of pull_request
# closed (merged) event because github token doesn't have write permission
# for pull_request from fork repository.
branches:
- master
tags:
- 'v*.*.*'
pull_request:
types:
- labeled

jobs:
release:
if: github.event.action != 'labeled'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Bump version on merging Pull Requests with specific labels. (bump:major,bump:minor,bump:patch)
- id: bumpr
if: "!startsWith(github.ref, 'refs/tags/')"
name: haya14busa/action-bumpr
uses: ./

# Update corresponding major and minor tag. e.g. Update v1 and v1.2 when releasing v1.2.3
- uses: haya14busa/action-update-semver@v1
if: "!steps.bumpr.outputs.skip"
with:
github_token: ${{ secrets.github_token }}
tag: ${{ steps.bumpr.outputs.next_version }}

# Get tag name.
- id: tag
uses: haya14busa/action-cond@v1
with:
cond: "${{ startsWith(github.ref, 'refs/tags/') }}"
if_true: ${{ github.ref }}
if_false: ${{ steps.bumpr.outputs.next_version }}

# Create release.
- uses: actions/create-release@v1
if: "steps.tag.outputs.value != ''"
env:
# This token is provided by Actions, you do not need to create your own token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.value }}
release_name: Release ${{ steps.tag.outputs.value }}
body: ${{ steps.bumpr.outputs.message }}
draft: false
prerelease: false

release-check:
if: github.event.action == 'labeled'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Post bumpr status comment
- name: haya14busa/action-bumpr
uses: ./
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Action test
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Test action
uses: ./
id: Test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Files to ignore
*.code-workspace

# Folders to ignore
.vscode/
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.10

ENV BUMP_VERSION=v1.1.0

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

RUN apk --no-cache add git jq grep curl
RUN wget -O - -q | sh -s -- -b /usr/local/bin/ ${BUMP_VERSION}

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
# action-get-semver

A simple action that returns the current/next major, minor, and patch version based on the given semver
version.

[![Test](https://github.com/rickstaa/action-get-semver/workflows/Test/badge.svg)](https://github.com/riokstaa/action-get-semver/actions?query=workflow%3ATest)
[![release](https://github.com/rickstaa/action-get-semver/workflows/release/badge.svg)](https://github.com/rickstaa/action-get-semver/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/rickstaa/action-bumpr?logo=github&sort=semver)](https://github.com/rickstaa/action-get-semver/releases)

## Input

```yaml
inputs:
bump_level:
description: "Version bump level [major,minor,patch]."
required: False
default: "patch"
outputs:
current_version:
description: "The current version."
next_version:
description: "The next major version."
```
## Usage
```yaml
name: release
on:
push:
branches:
- master
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rickstaa/action-get-semver@v1
with:

- name: Print semver
id: get_semver
with:
bump_level: "minor"
run: |
echo "Current version: ${{ steps.get_semver.outputs.current_version }}"
echo "Next version: ${{ steps.get_semver.outputs.next_version }}"
```
### Acknowledgement
This action serves as a wrapper around the [bump](https://github.com/haya14busa/bump) package of [@haya14busa](https://github.com/haya14busa/bump/commits?author=haya14busa).
20 changes: 20 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Get Semver"
description: "Get current/next major, minor, and patch version based on the given semver version."
author: "Rick Staa"
inputs:
bump_level:
description: "Version bump level [major,minor,patch]."
required: False
default: "patch"
outputs:
current_version:
description: "The current version."
next_version:
description: "The next major version."
runs:
using: "docker"
image: "Dockerfile"

branding:
icon: "corner-right-up"
color: "gray-dark"
25 changes: 25 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
set -e

if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}" || exit
fi

input_bump_level="$(echo $INPUT_BUMP_LEVEL | tr '[:upper:]' '[:lower:]')" # Make lowercase
case $input_bump_level in
"major"|"minor"|"patch")
;;
*)
printf '%s\n' "Please specify a valid bump level \`${input_bump_level}\` is not valid [major, minor, patch]."
exit 1
;;
esac

git fetch --tags # Fetch existing tags before bump.
# Fetch history as well because bump uses git history (git tag --merged).
git fetch --prune --unshallow
CURRENT_VERSION="$(bump current)" || true
NEXT_VERSION="$(bump ${input_bump_level})" || true

echo "::set-output name=current_version::${CURRENT_VERSION}"
echo "::set-output name=next_version::${NEXT_VERSION}"

0 comments on commit 789dcbe

Please sign in to comment.