Skip to content

Commit

Permalink
Merge pull request #6 from snow-actions/workflows
Browse files Browse the repository at this point in the history
Increment version
  • Loading branch information
SnowCait authored Dec 16, 2022
2 parents 5d08518 + 8efb6f8 commit e195891
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/increment-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Increment version

on:
workflow_dispatch:
inputs:
increment-version:
description: Increment version (Semantic Versioning)
required: true
default: patch
type: choice
options:
- major
- minor
- patch

jobs:
increment-version:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Latest version
run: |
set -x
tag=$(gh api /repos/${GITHUB_REPOSITORY}/releases/latest --jq '.tag_name')
echo "LATEST_VERSION=$tag" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ github.token }}
- name: Next version
id: next-version
run: |
set -x
if [[ ${LATEST_VERSION} =~ ^(.*?)([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
prefix=${BASH_REMATCH[1]}
major=${BASH_REMATCH[2]}
minor=${BASH_REMATCH[3]}
patch=${BASH_REMATCH[4]}
else
exit 1
fi
case "$INCREMENT_VERSION" in
"major")
((++major)); minor=0; patch=0;;
"minor")
((++minor)); patch=0;;
"patch")
((++patch));;
esac
next_version="${prefix}${major}.${minor}.${patch}"
echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV
env:
INCREMENT_VERSION: ${{ github.event.inputs.increment-version }}

- uses: actions/checkout@v3
- name: Update README
id: version
run: |
set -x
sed -i -e "s|${GITHUB_REPOSITORY}@${LATEST_VERSION}|${GITHUB_REPOSITORY}@${NEXT_VERSION}|g" README.md
git diff
- uses: snow-actions/git-config-user@v1.0.0
- id: generate-token
uses: tibdex/github-app-token@v1.7.0
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Commit & PR
run: |
set -x
branch="release/${NEXT_VERSION}"
git switch -c ${branch}
git add .
git commit -m "${NEXT_VERSION}"
git push origin ${branch}
gh pr create --base ${GITHUB_REF_NAME} --head ${branch} --assignee ${GITHUB_ACTOR} --title ${NEXT_VERSION} --body ''
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
pull_request:
types: [ closed ]
workflow_dispatch:
inputs:
version:
description: Semantic version (e.g. v1.0.0)
required: true

jobs:
release:
if: >-
github.event_name == 'workflow_dispatch' ||
github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- id: generate-token
uses: tibdex/github-app-token@v1.7.0
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Create release
id: release
run: |
version=${RELEASE_BRANCH#release/}
gh release create ${version} --title ${version} --generate-notes
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
GH_REPO: ${{ github.repository }}
RELEASE_BRANCH: ${{ github.event.pull_request.head.ref || github.event.inputs.version }}
23 changes: 23 additions & 0 deletions .github/workflows/released.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Released

on:
release:
types: [ released ]

jobs:
tweet:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Tweet
uses: snow-actions/tweet@v1.3.0
with:
status: |
Release ${{ github.event.release.name }} · ${{ github.repository }}
${{ github.event.release.html_url }}
env:
CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
CONSUMER_API_SECRET_KEY: ${{ secrets.TWITTER_CONSUMER_API_SECRET_KEY }}
ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

0 comments on commit e195891

Please # to comment.