Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 8b90dca

Browse files
add workflows
1 parent 44d1bf4 commit 8b90dca

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

.github/workflows/lint-and-fmt.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: lint and check format
2+
3+
on: push
4+
5+
jobs:
6+
lint-and-fmt:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 1
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Setup Deno
14+
uses: denoland/setup-deno@v1
15+
with:
16+
deno-version: v1.x
17+
18+
- name: Lint
19+
run: deno lint
20+
21+
- name: Check format
22+
run: deno fmt --check

.github/workflows/push-to-release.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: push-to-release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
get-release-mode:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 1
11+
outputs:
12+
mode: ${{ steps.output-mode.outputs.mode }}
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Get first line of commit message
17+
env:
18+
MESSAGE: ${{ github.event.head_commit.message }}
19+
run: |
20+
echo -e "MESSAGE_1=$MESSAGE" | head -n 1 >> $GITHUB_ENV
21+
22+
- name: Output mode
23+
id: output-mode
24+
env:
25+
IS_MAJOR: ${{ contains(env.MESSAGE_1, '[release major]') }}
26+
IS_MINOR: ${{ contains(env.MESSAGE_1, '[release minor]') }}
27+
IS_PATCH: ${{ contains(env.MESSAGE_1, '[release patch]') }}
28+
run: |
29+
if [[ "$IS_MAJOR" == "true" ]]; then
30+
MODE="M"
31+
elif [[ "$IS_MINOR" == "true" ]]; then
32+
MODE="m"
33+
elif [[ "$IS_PATCH" == "true" ]]; then
34+
MODE="p"
35+
else
36+
MODE="none"
37+
fi
38+
echo "mode=$MODE" >> $GITHUB_OUTPUT
39+
40+
create-tag-and-release:
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 1
43+
needs: get-release-mode
44+
if: ${{ needs.get-release-mode.outputs.mode != 'none' }}
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Get latest release version
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
REPO_NAME: ${{ github.repository }}
52+
run: |
53+
JSON_TEXT=$(curl -sSL \
54+
-H "Accept: application/vnd.github+json" \
55+
-H "Authorization: Bearer $GITHUB_TOKEN" \
56+
-H "X-GitHub-Api-Version: 2022-11-28" \
57+
https://api.github.com/repos/$REPO_NAME/releases/latest \
58+
)
59+
VERSION=$(echo "$JSON_TEXT" | jq ".tag_name" | sed -E 's/^"v?//' | sed -E 's/"$//')
60+
echo "VERSION=$VERSION" >> $GITHUB_ENV
61+
62+
- name: Increase version
63+
run: |
64+
curl -sSL https://raw.githubusercontent.com/fmahnke/shell-semver/master/increment_version.sh > increment_version.sh
65+
VERSION=$(bash increment_version.sh -${{ needs.get-release-mode.outputs.mode }} $VERSION)
66+
echo "TAG_NAME=v$VERSION" >> $GITHUB_ENV
67+
68+
- name: Add tag ${{ env.TAG_NAME }}
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
REPO_NAME: ${{ github.repository }}
72+
MESSAGE: ${{ toJson(github.event.head_commit.message) }}
73+
SHA: ${{ github.sha }}
74+
run: |
75+
curl -L \
76+
-X POST \
77+
-H "Accept: application/vnd.github+json" \
78+
-H "Authorization: Bearer $GITHUB_TOKEN" \
79+
-H "X-GitHub-Api-Version: 2022-11-28" \
80+
https://api.github.com/repos/$REPO_NAME/git/tags \
81+
-d "{\"tag\":\"$TAG_NAME\",\"message\":$MESSAGE,\"object\":\"$SHA\",\"type\":\"commit\"}"
82+
83+
- name: Create release ${{ env.TAG_NAME }}
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
REPO_NAME: ${{ github.repository }}
87+
MESSAGE: ${{ toJson(github.event.head_commit.message) }}
88+
SHA: ${{ github.sha }}
89+
NAME: Release ${{ env.TAG_NAME }}
90+
DRAFT: false
91+
PRERELEASE: false
92+
GENERATE_RELEASE_NOTES: true
93+
run: |
94+
curl -L \
95+
-X POST \
96+
-H "Accept: application/vnd.github+json" \
97+
-H "Authorization: Bearer $GITHUB_TOKEN" \
98+
-H "X-GitHub-Api-Version: 2022-11-28" \
99+
https://api.github.com/repos/$REPO_NAME/releases \
100+
-d "{\"tag_name\":\"$TAG_NAME\",\"target_commitish\":\"$SHA\",\"name\":\"$NAME\",\"body\":$MESSAGE,\"draft\":$DRAFT,\"prerelease\":$PRERELEASE,\"generate_release_notes\":$GENERATE_RELEASE_NOTES}"

0 commit comments

Comments
 (0)