Skip to content

Commit

Permalink
feat: Add action v1.0 (#1)
Browse files Browse the repository at this point in the history
* feat: first version added

* fix: correct test.yml

* fix: add path default in action.yaml

* fix: bad substitution

* fix: use github workspace from context, don't break path :(

* test: uses another repo for testing purposes

* test: Update test.yml

* test: fix bad checkout

* test: modify path

* test: use semver 7.X in repo

* test: fix two problems

* test: add change dir

* test: try configuring user

* test: rectify old_sha declaration

* test: add debug

* test: correct condition

* test: remove debug

* test: add depht limit

* test: try with a little reset

* test: correct yml

* test: bashenanigans

* test: try reseting to Commit, so pr in detached state

* test: checkout base branch

* test: remove, it works

* test: remove on content
  • Loading branch information
zckv authored Aug 8, 2023
1 parent 2011865 commit 552ccd3
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "13:00"
commit-message:
prefix: "fix: "
8 changes: 8 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"config:base"
],
"labels": [
"bump:patch"
]
}
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: release
on:
push:
branches:
- master
tags:
- 'v*.*.*'
pull_request:
types:
- labeled

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

# 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: shogo82148/actions-create-release@v1
if: "steps.tag.outputs.value != ''"
with:
# This token is provided by Actions, you do not need to create your own token
github_token: ${{ secrets.GITHUB_TOKEN }}
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@v3
- name: Post bumpr status comment
uses: haya14busa/action-bumpr@v1
46 changes: 46 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: reviewdog
on:
push:
branches:
- master
pull_request:
jobs:
shellcheck:
name: runner / shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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

misspell:
name: runner / misspell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: warning
locale: "US"

alex:
name: runner / alex
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-alex@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: warning
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test
on: []

permissions:
contents: write
pull-requests: write

jobs:
semver-check:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: 3.8
- uses: actions/checkout@v3
with:
repository: zckv/semantic-versioning-example
path: ./pyproject/
fetch-depth: 0
ref: revert_to_7.X
- uses: actions/checkout@v3
with:
path: ./pyaction/
# Test the action with no enabled steps.
- name: Test Action
uses: ./pyaction/
with:
path: ./pyproject/
base: revert_to_7.X
141 changes: 141 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: 'Semantic Release'
description: 'Use python semantic release 7 in a composite action. The result is pushed in a pull request, for repositories where the main branch is protected.'
author: 'Zackarie Vinckier <[email protected]>'

inputs:
# Python Project Configuration is expected to be in a pyproject.toml
token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
default: ${{ github.token }}
path:
description: >
Relative path under $GITHUB_WORKSPACE to the repository.
Defaults to $GITHUB_WORKSPACE.
add-paths:
description: >
A comma or newline-separated list of file paths to commit.
Paths should follow git's pathspec syntax.
Defaults to adding all new and modified files.
commit-message:
description: 'The message to use when committing changes.'
default: '[create-pull-request] automated change'
committer:
description: >
The committer name and email address in the format `Display Name <[email protected]>`.
Defaults to the GitHub Actions bot user.
default: 'GitHub <[email protected]>'
author:
description: >
The author name and email address in the format `Display Name <[email protected]>`.
Defaults to the user who triggered the workflow run.
default: '${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>'
signoff:
description: 'Add `Signed-off-by` line by the committer at the end of the commit log message.'
default: false
branch:
description: 'The pull request branch name.'
default: 'create-pull-request/patch'
delete-branch:
description: >
Delete the `branch` when closing pull requests, and when undeleted after merging.
Recommend `true`.
default: false
branch-suffix:
description: 'The branch suffix type when using the alternative branching strategy.'
base:
description: >
The pull request base branch.
Defaults to the branch checked out in the workflow.
push-to-fork:
description: >
A fork of the checked out parent repository to which the pull request branch will be pushed.
e.g. `owner/repo-fork`.
The pull request will be created to merge the fork's branch into the parent's base.
title:
description: 'The title of the pull request.'
default: 'Changes by create-pull-request action'
body:
description: 'The body of the pull request.'
default: 'Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action'
body-path:
description: 'The path to a file containing the pull request body. Takes precedence over `body`.'
labels:
description: 'A comma or newline separated list of labels.'
assignees:
description: 'A comma or newline separated list of assignees (GitHub usernames).'
reviewers:
description: 'A comma or newline separated list of reviewers (GitHub usernames) to request a review from.'
team-reviewers:
description: >
A comma or newline separated list of GitHub teams to request a review from.
Note that a `repo` scoped Personal Access Token (PAT) may be required.
milestone:
description: 'The number of the milestone to associate the pull request with.'
draft:
description: 'Create a draft pull request. It is not possible to change draft status after creation except through the web interface'
default: false
runs:
using: "composite"
steps:
- name: Install semantic versionning
shell: bash
run: |
# The old 7.X version is needed
python -m pip install python-semantic-release==7.34.6
- name: Use semver for commit
id: semver
shell: bash
env:
WPATH: ${{ inputs.path }}
AUTHOR: ${{ inputs.committer }}
GITHUB_WORKSPACE: ${{ github.workspace }}
BRANCH: ${{ inputs.base }}
run: |
export WPATH=${WPATH:=$GITHUB_WORKSPACE}
cd "$WPATH"
git switch $BRANCH
git config user.name $(echo $AUTHOR | cut -d ' ' -f1)
git config user.email $(echo $AUTHOR | cut -d ' ' -f2)
echo "old_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
semantic-release version -v DEBUG
echo "new_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "msg=$(echo '"'$(git log -1 --pretty=%B)'"')" >> "$GITHUB_OUTPUT"
- name: Reset HEAD
shell: bash
if: ${{ steps.semver.outputs.old_sha != steps.semver.outputs.new_sha }}
env:
OLD_SHA: ${{ steps.semver.outputs.old_sha }}
WPATH: ${{ inputs.path }}
run: |
export WPATH=${WPATH:=$GITHUB_WORKSPACE}
cd "$WPATH"
git reset $OLD_SHA
- uses: peter-evans/create-pull-request@v5
if: ${{ steps.semver.outputs.old_sha != steps.semver.outputs.new_sha }}
with:
token: ${{ inputs.token }}
path: ${{ inputs.path }}
add-paths: ${{ inputs.add-path }}
commit-message: ${{ steps.semver.outputs.msg }}
committer: ${{ inputs.committer }}
author: ${{ inputs.author }}
signoff: ${{ inputs.signoff }}
branch: ${{ inputs.branch }}
delete-branch: ${{ inputs.delete-branch }}
branch-suffix: ${{ inputs.branch-suffix }}
base: ${{ inputs.base }}
push-to-fork: ${{ inputs.push-to-fork }}
title: ${{ inputs.title }}
body: ${{ inputs.body }}
body-path: ${{ inputs.body-path }}
labels: ${{ inputs.labels }}
assignees: ${{ inputs.assignees }}
reviewers: ${{ inputs.reviewers }}
team-reviewers: ${{ inputs.team-reviewers }}
milestone: ${{ inputs.milestone }}
draft: ${{ inputs.draft }}

# Ref: https://haya14busa.github.io/github-action-brandings/
branding:
icon: 'check-circle'
color: 'green'

0 comments on commit 552ccd3

Please sign in to comment.