This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
84 lines (75 loc) · 2.99 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Master
on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- '*.md'
jobs:
get-publish-version:
runs-on: ubuntu-latest
outputs:
publish-version: ${{ steps.get-publish-version.outputs.publish-version }}
steps:
- name: Prepare SemVer
id: prepare-semver
run: |
set +o pipefail
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
set -o pipefail
[ -z "$LATEST_VERSION" ] && LATEST_VERSION="0.0.0"
echo "latest_version_out=${LATEST_VERSION:1}" >> $GITHUB_OUTPUT
VERSION=$(echo $LATEST_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
commit_message=$( echo "${{ github.event.head_commit.message }}" | sed 's/"//g')
if [[ "${commit_message,,}" == *"major release"* ]]; then
echo "semver_increment=m" >> $GITHUB_OUTPUT
elif [[ "${commit_message,,}" == *"minor release"* ]]; then
echo "semver_increment=i" >> $GITHUB_OUTPUT
else
echo "semver_increment=p" >> $GITHUB_OUTPUT
fi
- name: Increment SemVer
id: semver
uses: matt-FFFFFF/[email protected]
with:
semver-input: ${{ steps.prepare-semver.outputs.latest_version_out }}
increment: ${{ steps.prepare-semver.outputs.semver_increment }}
- name: Get publish version
id: get-publish-version
run: |
echo "publish-version=v${{ steps.semver.outputs.semver }}" >> $GITHUB_OUTPUT
build-and-publish-github-release:
runs-on: ubuntu-latest
needs: [get-publish-version]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: install dependencies
run: |
set +o pipefail
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
set -o pipefail
[ -z "$LATEST_VERSION" ] && LATEST_VERSION="0.0.0"
VERSION=$(echo $LATEST_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
VERSION_NUMBER=$(echo $VERSION | sed 's/^v\(.*\)$/\1/')
echo ${VERSION} > VERSION
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.get-publish-version.outputs.publish-version }}
release_name: ${{ needs.get-publish-version.outputs.publish-version }}
draft: false
prerelease: false
- name: upload VERSION file
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: VERSION
asset_name: VERSION
asset_content_type: text/plain