Skip to content

Commit a1abc30

Browse files
committed
chore(github): workflows
1 parent b2342f7 commit a1abc30

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: 'npm' # See documentation for possible values
9+
directory: '/' # Location of package manifests
10+
target-branch: 'develop'
11+
schedule:
12+
interval: 'daily'
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Create Release PR
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
semver:
6+
description: "New Version(semver)"
7+
required: true
8+
default: "patch"
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
create-release-pr:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: checkout
23+
uses: actions/checkout@v3
24+
- name: Update Version
25+
run: |
26+
git config --global user.email "${GIT_AUTHOR_EMAIL}"
27+
git config --global user.name "${GIT_AUTHOR_NAME}"
28+
npm run ci:versionup:${SEMVER} --yes
29+
env:
30+
SEMVER: ${{ github.event.inputs.semver }}
31+
GIT_AUTHOR_NAME: ${{ github.actor }}
32+
GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com
33+
- name: Set PACKAGE_VERSION
34+
run: echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
35+
- name: Set GitHub Release Note
36+
id: release_note
37+
uses: actions/github-script@v6
38+
with:
39+
script: |
40+
const result = await exec.getExecOutput(`gh api "/repos/{owner}/{repo}/releases/generate-notes" -f tag_name="v${process.env.PACKAGE_VERSION}" --jq .body`, [], {
41+
ignoreReturnCode: true,
42+
})
43+
core.setOutput('stdout', result.stdout)
44+
env:
45+
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
- name: Create Pull Request
48+
id: cpr
49+
uses: peter-evans/create-pull-request@v4
50+
with:
51+
token: ${{ secrets.GITHUB_TOKEN }}
52+
commit-message: "chore(release): v${{ env.PACKAGE_VERSION }}"
53+
committer: GitHub <noreply@github.com>
54+
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
55+
assignees: ${{ github.actor }}
56+
signoff: false
57+
branch: release/${{ env.PACKAGE_VERSION }}
58+
branch-suffix: timestamp
59+
delete-branch: true
60+
title: "v${{ env.PACKAGE_VERSION }}"
61+
body: |
62+
${{ steps.release_note.outputs.stdout }}
63+
labels: "Type: Release"
64+
- name: Check Pull Request
65+
run: |
66+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
67+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Dependabot auto-merge
2+
on: pull_request
3+
4+
permissions:
5+
contents: write
6+
pull-requests: write
7+
8+
jobs:
9+
dependabot:
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.user.login == 'dependabot[bot]'
12+
steps:
13+
- name: Dependabot metadata
14+
id: metadata
15+
uses: dependabot/fetch-metadata@v2
16+
with:
17+
github-token: '${{ secrets.GITHUB_TOKEN }}'
18+
- name: Enable auto-merge for Dependabot PRs
19+
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
20+
run: |
21+
gh pr review --approve "$PR_URL"
22+
gh pr merge --auto --merge "$PR_URL"
23+
env:
24+
PR_URL: ${{ github.event.pull_request.html_url }}
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types: [closed]
8+
workflow_dispatch: # force release
9+
10+
jobs:
11+
check:
12+
permissions:
13+
contents: read
14+
runs-on: ubuntu-latest
15+
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
16+
outputs:
17+
EXISTS_TAG: ${{ steps.tag_check.outputs.EXISTS_TAG }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
- name: Set PACKAGE_VERSION
22+
run: echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
23+
- name: Tag Check
24+
id: tag_check
25+
run: |
26+
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}"
27+
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
28+
-H "Authorization: token ${GITHUB_TOKEN}")
29+
if [ "$http_status_code" -ne "404" ] ; then
30+
echo "EXISTS_TAG=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "EXISTS_TAG=false" >> $GITHUB_OUTPUT
33+
fi
34+
env:
35+
TAG_NAME: v${{ env.PACKAGE_VERSION }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
release:
38+
runs-on: ubuntu-latest
39+
needs: check
40+
if: always() && (needs.check.outputs.EXISTS_TAG == 'false')
41+
permissions:
42+
contents: write
43+
issues: write
44+
pull-requests: write
45+
packages: write
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v3
49+
- name: Setup Node
50+
uses: actions/setup-node@v3
51+
with:
52+
node-version: 20
53+
- name: Git Identity
54+
run: |
55+
git config --global user.name 'github-actions[bot]'
56+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
57+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
- name: Set PACKAGE_VERSION
61+
run: echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
62+
- name: Create Git Tag
63+
uses: pkgdeps/git-tag-action@v2
64+
with:
65+
version: ${{ env.PACKAGE_VERSION }}
66+
github_token: ${{ secrets.GITHUB_TOKEN }}
67+
github_repo: ${{ github.repository }}
68+
git_commit_sha: ${{ github.sha }}
69+
git_tag_prefix: "v"
70+
- name: Create Release
71+
id: create_release
72+
uses: softprops/action-gh-release@v1
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
tag_name: v${{ env.PACKAGE_VERSION }}
77+
release_name: ${{ github.event.pull_request.title }}
78+
body: ${{ github.event.pull_request.body }}
79+
draft: false
80+
prerelease: false
81+
generate_release_notes: ${{ !github.event.pull_request.body }}
82+
- uses: actions/github-script@v6
83+
if: github.event_name != 'workflow_dispatch'
84+
with:
85+
github-token: ${{secrets.GITHUB_TOKEN}}
86+
script: |
87+
github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: '🎉 Release https://github.com/${{ github.repository }}/releases/tag/v${{ env.PACKAGE_VERSION }}'
92+
})

0 commit comments

Comments
 (0)