Skip to content

Commit

Permalink
Merge branch 'upstream-master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	entrypoint.sh
  • Loading branch information
scottmessinger committed Jun 16, 2021
2 parents b3310b4 + 73f136c commit 80efee2
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 46 deletions.
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Basic dependabot.yml file with
# minimum configuration for two package managers

version: 2
updates:
# Enable version updates for GitHub Actions
- package-ecosystem: "github-actions"
# Look for GitHub Actions workflows in the `root` directory
directory: "/"
# Check the for updates once a week
schedule:
interval: "weekly"

# Enable version updates for Docker
- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `root` directory
directory: "/"
# Check for updates once a week
schedule:
interval: "weekly"
74 changes: 72 additions & 2 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,83 @@ on:
pull_request:
branches: [ master ]

env:
IMAGE_NAME: generate-changelog-action

jobs:

build:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag generate-changelog-action:$(date +%s)
run: docker build . --file Dockerfile --tag generate-changelog-action

- name: Docker run
run: docker run --entrypoint generate-changelog generate-changelog-action --version

- name: Test generating changelog
run: docker run -e REPO=${{ github.repository }} generate-changelog-action

lint:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://github/super-linter:v2.2.0
env:
VALIDATE_ALL_CODEBASE: true

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
permissions:
packages: write
contents: read
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
SHA="${{ github.sha }}"
# Strip git ref prefix from version
REF=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
echo IMAGE_ID=$IMAGE_ID
echo SHA=$SHA
echo REF=$REF
docker tag $IMAGE_NAME $IMAGE_ID:$SHA
docker tag $IMAGE_NAME $IMAGE_ID:$REF
docker push $IMAGE_ID:$SHA
docker push $IMAGE_ID:$REF
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Changelog
uses: scottbrenner/generate-changelog-action@master
id: Changelog
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
${{ steps.Changelog.outputs.changelog }}
draft: false
prerelease: false
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM alpine:3

RUN apk --no-cache add git nodejs-npm
LABEL org.opencontainers.image.source="https://github.com/ScottBrenner/generate-changelog-action"

RUN apk --no-cache add git npm
RUN npm install -g generate-changelog

COPY LICENSE README.md /
Expand Down
80 changes: 39 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
# generate-changelog-action

GitHub Action for [lob/generate-changelog](https://github.com/lob/generate-changelog/). Intended to be used with [actions/create-release](https://github.com/actions/create-release) as follows:
GitHub Action for [lob/generate-changelog](https://github.com/lob/generate-changelog/). Intended to be used with [actions/create-release](https://github.com/actions/create-release).

### Example workflow - create a release
Extends [actions/create-release: Example workflow - create a release](https://github.com/actions/create-release#example-workflow---create-a-release) to generate changelog from git commits and use it as the body for the GitHub release.
Created during the GitHub Actions Hackathon 2020 and [selected as one of the winning projects!](https://docs.google.com/spreadsheets/d/1YL6mjJXGt3-75GejQCubsOvWwtYcGaqbJA7msnsh7Tg/edit#gid=0&range=A100:C100)

## Usage

**Note:** [Your repository must contain a `package.json` file](https://github.com/lob/generate-changelog/issues/38#issuecomment-362726723), although an empty file such as [the one in this repository](https://github.com/ScottBrenner/generate-changelog-action/blob/master/package.json) is fine.

If your `package.json` isn't available in root directory of your repository, you can pass the path of the `package.json` file by setting `package-dir` as follows:

```yaml
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: changelog
uses: scottbrenner/generate-changelog-action@master
id: Changelog
env:
REPO: ${{ github.repository }}
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
${{ steps.Changelog.outputs.changelog }}
draft: false
prerelease: false
- name: Changelog
uses: scottbrenner/generate-changelog-action@master
id: Changelog
with:
package-dir: 'root/to/my/package.json'
```
The above workflow will create a release that looks like:
![](release.png)
By default, this Action generates changelogs using commits between the previous tag and the most recent tag. Generate changelogs from specific tag or range (e.g. `v1.2.3` or `v1.2.3..v1.2.4`) by passing the `from-tag` and `to-tag` inputs. An example is when your release tag on git is generated after the changelog so you must use something like `git log v1..HEAD --oneline`:

```yaml
- name: Changelog
uses: scottbrenner/generate-changelog-action@master
id: Changelog
with:
from-tag: v1.0
to-tag: HEAD
```

This Action additionally supports the following inputs, in accordance with [lob/generate-changelog's CLI options](https://github.com/lob/generate-changelog/#cli).
| Property | Default | Description |
| ------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `package-dir` | `package.json`| The path for the package.json if it is not in root |
| `from-tag` | "last tag" | The tag to generate changelog from. If not set, fallbacks to git last tag -1. Ex.: v1.0 |
| `to-tag` | "current tag" | The tag to generate changelog up to. If not set, fallbacks to git last tag. Ex.: v2.0 |
| `type` | Unset | The type of changelog to generate: patch, minor, or major. If not set, fallbacks to unset. |
| `exclude` | Unset | Exclude selected commit types (comma separated). If not set, fallbacks to unset. |
| `allow-unknown` | Unset | Allow unknown commit types. If not set, fallbacks to unset.

For more information, see [actions/create-release: Usage](https://github.com/actions/create-release#usage), [lob/generate-changelog: Usage](https://github.com/lob/generate-changelog#usage), and [jobs.<job_id>.steps[*].with](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith).


For more information, see [actions/create-release: Usage](https://github.com/actions/create-release#usage) and [lob/generate-changelog: Usage](https://github.com/lob/generate-changelog#usage)
## Example workflow - create a release
See [this repository's release.yml](https://github.com/ScottBrenner/generate-changelog-action/blob/master/.github/workflows/release.yml) for an example workflow which extends [actions/create-release: Example workflow - create a release](https://github.com/actions/create-release#example-workflow---create-a-release) to generate a changelog from git commits and use it as the body for the GitHub release.

_Created during the GitHub Actions Hackathon 2020._
This workflow automatically creates [this repository's releases](https://github.com/ScottBrenner/generate-changelog-action/releases).
32 changes: 32 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,41 @@ author: 'Scott Brenner'
outputs:
changelog:
description: 'Generate changelog'
inputs:
package-dir:
description: 'The path for the package.json if it is not in root'
required: false
default: 'package.json'
from-tag:
description: 'The tag to generate changelog from'
required: false
default: ''
to-tag:
description: 'The tag to generate changelog up to'
required: false
default: ''
type:
description: 'Type of changelog: patch, minor, or major'
required: false
default: ''
exclude:
description: 'Exclude selected commit types (comma separated)'
required: false
default: ''
allow-unknown:
description: 'Allow unknown commit types'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
env:
PACKAGE_DIR: ${{ inputs.package-dir }}
FROM_TAG: ${{ inputs.from-tag }}
TO_TAG: ${{ inputs.to-tag }}
TYPE: ${{ inputs.type }}
EXCLUDE: ${{ inputs.exclude }}
ALLOW_UNKNOWN: ${{ inputs.allow-unknown }}
branding:
icon: 'edit'
color: 'gray-dark'
58 changes: 56 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,70 @@
#!/bin/sh -l
# shellcheck disable=SC2039

git clone --quiet https://github.com/$REPO &> /dev/null
# For Docker Image CI test job
if [ "$REPO" = "ScottBrenner/generate-changelog-action" ]; then
git clone --quiet https://github.com/"$REPO"
cd generate-changelog-action || exit
fi

echo "Generating commit range for the following tag range:"
echo $TAG_RANGE

changelog=$(generate-changelog $* --tag $TAG_RANGE --file -)

echo $changelog
if [ -z "$FROM_TAG" ]; then
echo "No from-tag passed. Fallbacking to git previous tag."
previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1)
else
echo "From-tag detected. Using its value."
previous_tag=$FROM_TAG
fi

if [ -z "$TO_TAG" ]; then
echo "No to-tag passed. Fallbacking to git previous tag."
new_tag=$(git tag --sort version:refname | tail -n 1)
else
echo "To-tag detected. Using its value."
new_tag=$TO_TAG
fi

if [ -z "$TYPE" ]; then
echo "No type passed. Fallbacking to unset."
else
echo "Type detected. Using its value."
case $TYPE in
patch)
changelog_type="--patch"
;;
minor)
changelog_type="--minor"
;;
major)
changelog_type="--major"
;;
esac
fi

if [ -z "$EXCLUDE" ]; then
echo "No commit types selected to exclude. Fallbacking to unset."
else
echo "Commit types selected to exclude. Using its value."
exclude_types="--exclude $EXCLUDE"
fi

if [ -z "$ALLOW_UKNOWN" ]; then
echo "Unknown commit types not allowed."
else
echo "Allowing unknown commit types."
unknown_commits="--allow-unknown "
fi

changelog=$(generate-changelog "$changelog_type" -t "$previous_tag..$new_tag" "$exclude_types" "$unknown_commits" --file -)

changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"

echo "$changelog"

echo "::set-output name=changelog::$changelog"
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Binary file removed release.png
Binary file not shown.

0 comments on commit 80efee2

Please sign in to comment.