Skip to content

Commit b65bf97

Browse files
authored
Merge pull request #115 from proyecto26/feature/semantic-release
feat(ci): automated release workflow with semantic versioning
2 parents 31d9d7e + 949bf48 commit b65bf97

File tree

7 files changed

+269
-157
lines changed

7 files changed

+269
-157
lines changed

.github/workflows/release.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
inputs:
9+
version_bump:
10+
description: 'Version bump type'
11+
required: true
12+
default: 'patch'
13+
type: choice
14+
options:
15+
- patch
16+
- minor
17+
- major
18+
release_notes:
19+
description: 'Additional release notes (optional)'
20+
required: false
21+
type: string
22+
23+
permissions:
24+
contents: write
25+
26+
jobs:
27+
release:
28+
name: Create Release
29+
runs-on: ubuntu-latest
30+
outputs:
31+
new_version: ${{ steps.version.outputs.new_version }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Get current version
39+
id: current
40+
run: |
41+
CURRENT=$(node -p "require('./src/package.json').version")
42+
echo "version=$CURRENT" >> $GITHUB_OUTPUT
43+
echo "Current version: $CURRENT"
44+
45+
- name: Determine version bump from commits
46+
id: bump
47+
run: |
48+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
49+
echo "type=${{ inputs.version_bump }}" >> $GITHUB_OUTPUT
50+
else
51+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
52+
if [ -z "$LAST_TAG" ]; then RANGE="HEAD"; else RANGE="${LAST_TAG}..HEAD"; fi
53+
COMMITS=$(git log $RANGE --pretty=format:"%s" 2>/dev/null || echo "")
54+
if echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?!:|BREAKING CHANGE"; then
55+
echo "type=major" >> $GITHUB_OUTPUT
56+
elif echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
57+
echo "type=minor" >> $GITHUB_OUTPUT
58+
else
59+
echo "type=patch" >> $GITHUB_OUTPUT
60+
fi
61+
fi
62+
63+
- name: Calculate new version
64+
id: version
65+
run: |
66+
IFS='.' read -r MAJOR MINOR PATCH <<< "${{ steps.current.outputs.version }}"
67+
case "${{ steps.bump.outputs.type }}" in
68+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
69+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
70+
patch) PATCH=$((PATCH + 1)) ;;
71+
esac
72+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
73+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
74+
echo "New version: $NEW_VERSION"
75+
76+
- name: Generate changelog entry
77+
id: changelog
78+
run: |
79+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
80+
if [ -z "$LAST_TAG" ]; then RANGE="HEAD"; else RANGE="${LAST_TAG}..HEAD"; fi
81+
82+
TODAY=$(date +%Y-%m-%d)
83+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
84+
ADDED="" CHANGED="" FIXED="" REMOVED=""
85+
86+
while IFS= read -r line; do
87+
HASH=$(echo "$line" | cut -d'|' -f1)
88+
MSG=$(echo "$line" | cut -d'|' -f2-)
89+
SHORT_HASH=$(echo "$HASH" | cut -c1-7)
90+
PR_NUM=$(echo "$MSG" | grep -oP '\(#\K[0-9]+(?=\))' | head -1)
91+
92+
if [ -n "$PR_NUM" ]; then
93+
ATTR="([#${PR_NUM}](https://github.com/proyecto26/nativescript-inappbrowser/pull/${PR_NUM}))"
94+
else
95+
ATTR="([${SHORT_HASH}](https://github.com/proyecto26/nativescript-inappbrowser/commit/${HASH}))"
96+
fi
97+
98+
CLEAN_MSG=$(echo "$MSG" | sed -E 's/^(feat|fix|perf|refactor|chore|docs|style|test|build|ci)(\([^)]*\))?(!)?:\s*//')
99+
CLEAN_MSG=$(echo "$CLEAN_MSG" | sed -E 's/\s*\(#[0-9]+\)\s*$//')
100+
101+
if echo "$MSG" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
102+
ADDED="${ADDED}- ${CLEAN_MSG} ${ATTR}.\n"
103+
elif echo "$MSG" | grep -qiE "^fix(\(.+\))?:"; then
104+
FIXED="${FIXED}- ${CLEAN_MSG} ${ATTR}.\n"
105+
elif echo "$MSG" | grep -qiE "^(perf|refactor|chore|docs|style|build|ci)(\(.+\))?:"; then
106+
CHANGED="${CHANGED}- ${CLEAN_MSG} ${ATTR}.\n"
107+
elif echo "$MSG" | grep -qiE "^(revert)(\(.+\))?:"; then
108+
REMOVED="${REMOVED}- ${CLEAN_MSG} ${ATTR}.\n"
109+
else
110+
CHANGED="${CHANGED}- ${CLEAN_MSG} ${ATTR}.\n"
111+
fi
112+
done < <(git log $RANGE --pretty=format:"%H|%s" --no-merges 2>/dev/null)
113+
114+
if [ -n "${{ inputs.release_notes }}" ]; then
115+
ADDED="${ADDED}- ${{ inputs.release_notes }}\n"
116+
fi
117+
118+
BODY=""
119+
[ -n "$ADDED" ] && BODY="${BODY}### Added\n${ADDED}\n"
120+
[ -n "$CHANGED" ] && BODY="${BODY}### Changed\n${CHANGED}\n"
121+
[ -n "$FIXED" ] && BODY="${BODY}### Fixed\n${FIXED}\n"
122+
[ -n "$REMOVED" ] && BODY="${BODY}### Removed\n${REMOVED}\n"
123+
[ -z "$BODY" ] && BODY="### Changed\n- Release version ${NEW_VERSION}.\n"
124+
125+
echo -e "$BODY" > /tmp/release_body.md
126+
127+
# Update CHANGELOG.md
128+
PREV_VERSION="${{ steps.current.outputs.version }}"
129+
HEADER="## [${NEW_VERSION}] - ${TODAY}"
130+
LINK="[${NEW_VERSION}]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v${PREV_VERSION}...v${NEW_VERSION}"
131+
sed -i "/^## \[Unreleased\]/a\\\\n${HEADER}\\n" CHANGELOG.md
132+
sed -i "/^## \[${NEW_VERSION}\]/r /tmp/release_body.md" CHANGELOG.md
133+
sed -i "s|\[Unreleased\]: .*|[Unreleased]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v${NEW_VERSION}...HEAD|" CHANGELOG.md
134+
sed -i "/^\[Unreleased\]:/a ${LINK}" CHANGELOG.md
135+
136+
- name: Update version in src/package.json
137+
run: |
138+
node -e "
139+
const pkg = require('./src/package.json');
140+
pkg.version = '${{ steps.version.outputs.new_version }}';
141+
require('fs').writeFileSync('./src/package.json', JSON.stringify(pkg, null, '\t') + '\n');
142+
"
143+
144+
- name: Commit version bump
145+
run: |
146+
git config --global user.name 'github-actions[bot]'
147+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
148+
git add -A
149+
git commit -m "chore(release): v${{ steps.version.outputs.new_version }}
150+
151+
- Updated src/package.json
152+
- Updated CHANGELOG.md"
153+
git tag "v${{ steps.version.outputs.new_version }}"
154+
git push origin master --follow-tags
155+
156+
- name: Create GitHub Release
157+
uses: softprops/action-gh-release@v2
158+
with:
159+
tag_name: v${{ steps.version.outputs.new_version }}
160+
name: Release ${{ steps.version.outputs.new_version }}
161+
body_path: /tmp/release_body.md
162+
draft: false
163+
prerelease: false
164+
165+
publish-npm:
166+
name: Publish to npm
167+
needs: release
168+
runs-on: ubuntu-latest
169+
if: needs.release.outputs.new_version != ''
170+
steps:
171+
- uses: actions/checkout@v4
172+
with:
173+
ref: master
174+
175+
- name: Pull latest (includes version bump commit)
176+
run: git pull origin master
177+
178+
- name: Setup Node.js
179+
uses: actions/setup-node@v4
180+
with:
181+
node-version: '20'
182+
registry-url: 'https://registry.npmjs.org'
183+
184+
- name: Build and publish
185+
run: |
186+
cd src
187+
npm install
188+
npm run build || true
189+
npm publish
190+
env:
191+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.travis.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ You can further optimize performance and pre-render pages [by providing the urls
219219
constructor() {
220220
super();
221221
// Do not call this every time the component render
222-
InAppBrowser.mayLaunchUrl(this._url, [
222+
InAppBrowser.mayLaunchUrl("https://nativescript.org", [
223223
"https://twitter.com/NativeScript",
224224
"https://github.com/NativeScript/NativeScript",
225225
"https://openjsf.org"
@@ -364,11 +364,9 @@ Support this project with your organization. Your logo will show up here with a
364364
I believe in Unicorns 🦄
365365
Support [me](http://www.paypal.me/jdnichollsc/2), if you do too.
366366

367-
Donate **Ethereum**, **ADA**, **BNB**, **SHIBA**, **USDT**, **DOGE**:
367+
Donate **Ethereum**, **ADA**, **BNB**, **SHIBA**, **USDT/USDC**, **DOGE**, etc:
368368

369-
![Wallet address](https://user-images.githubusercontent.com/2154886/123501719-84bf1900-d60c-11eb-882c-98a499cea323.png)
370-
371-
> Wallet address: 0x3F9fA8021B43ACe578C2352861Cf335449F33427
369+
> Wallet address: jdnichollsc.eth
372370
373371
Please let us know your contributions! 🙏
374372

publish/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
node_modules/
12
*.map
23
*.ts
34
!*.d.ts

src/InAppBrowser.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ function setup() {
141141
}
142142

143143
const window = getWindow();
144-
const ctrl = window.rootViewController;
144+
// 8.3+ supports Utils.ios.getRootViewController
145+
const ctrl = Utils.ios.getRootViewController ? Utils.ios.getRootViewController() : window.rootViewController;
145146
if (modalEnabled) {
146147
// This is a hack to present the SafariViewController modally
147148
const safariHackVC =

0 commit comments

Comments
 (0)