From 634fa6d7b913faf0328140f15d743f31ec8fbaa3 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Mon, 11 Jan 2021 22:16:00 +0100 Subject: [PATCH] :sparkles: Adds action scripts --- .github/renovate.json | 5 +++ .github/workflows/code_quality.yml | 50 ++++++++++++++++++++++++++++ .github/workflows/dockerimage.yml | 9 +++++ .github/workflows/release.yml | 53 ++++++++++++++++++++++++++++++ .gitignore | 3 ++ .vscode/launch.json | 17 ++++++++++ Dockerfile | 8 +++++ LICENSE | 21 ++++++++++++ action.yml | 25 ++++++++++++++ entrypoint.sh | 37 +++++++++++++++++++++ 10 files changed, 228 insertions(+) create mode 100644 .github/renovate.json create mode 100644 .github/workflows/code_quality.yml create mode 100644 .github/workflows/dockerimage.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 action.yml create mode 100755 entrypoint.sh diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 0000000..8808656 --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,50 @@ +name: Code quality CI +on: + push: + branches: + - master + pull_request: +jobs: + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-cond@v1 + id: reporter + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: "github-pr-review" + if_false: "github-check" + - uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: ${{ steps.reporter.outputs.value }} + level: warning + hadolint: + name: runner / hadolint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-cond@v1 + id: reporter + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: "github-pr-review" + if_false: "github-check" + - uses: reviewdog/action-hadolint@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: ${{ steps.reporter.outputs.value }} + level: warning + misspell: + name: runner / misspell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: reviewdog/action-misspell@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + level: warning + locale: "US" diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..df147e4 --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,9 @@ +name: Docker Image CI +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag rickstaa-action-create-tag:$(date +%s) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bc025e0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: release +on: + push: + branches: + - main + 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/')" + uses: haya14busa/action-bumpr@v1 + # 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: + 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 + - name: Post bumpr status comment + uses: haya14busa/action-bumpr@v1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07a3305 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# IDE +.vsode/ +*.code-workspace diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b71bc12 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "bashdb", + "request": "launch", + "name": "Bash-Debug (simplest configuration)", + "program": "${file}", + "env": { + "INPUT_TAG": "v1.0.2" + } + } + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0fe9a49 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:3.10 + +RUN apk --no-cache add git && \ + rm -rf /var/lib/apt/lists/* + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..345fe89 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 haya14busa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..9ddb699 --- /dev/null +++ b/action.yml @@ -0,0 +1,25 @@ +name: "Create tag." +description: "Creates tags on a tag push." +author: "Rick Staa" +inputs: + github_token: + description: "GITHUB_TOKEN. Optional if you use checkout@v2 action." + default: "${{ github.token }}" + tag: + description: "Optional. Existing tag to update from. Default comes from $GITHUB_REF." + required: false + message: + description: "Tag message." + required: false + commit_sha: + description: The commit SHA hash on which you want to push the tag. Uses latest commit by default. + required: false + force_push_tag: + description: "Optional. Force push the tag. Defaults to 'false'." + required: false +runs: + using: "docker" + image: "Dockerfile" +branding: + icon: "tag" + color: "blue" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..57944a8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,37 @@ +#!/bin/sh +set -x + +cd "${GITHUB_WORKSPACE}" || exit + +if [ -z "${INPUT_TAG}" ]; then + echo "No-tag was supplied! Please supply a tag." + exit 1 +fi + +# Set up variables. +TAG="${INPUT_TAG}" +MESSAGE="${INPUT_MESSAGE:-Release ${TAG}}" +FORCE_TAG="${INPUT_FORCE_PUSH_TAG:-false}" + +# Set up Git credentials +git config user.name "${GITHUB_ACTOR}" +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + +# Update MAJOR/MINOR tag +if [ "${INPUT_FORCE_PUSH_TAG}" == 'true' ]; then + git tag -fa "${TAG}" -m "${MESSAGE}" +else + git tag -a "${TAG}" -m "${MESSAGE}" +fi + +# Set up remote url for checkout@v1 action. +if [ -n "${INPUT_GITHUB_TOKEN}" ]; then + git remote set-url origin "https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +fi + +# Push tag +if [ "${INPUT_FORCE_PUSH_TAG}" == 'true' ]; then + git push --force origin "${TAG}" +else + git push origin "${TAG}" +fi