Skip to content

Commit 74e8d2e

Browse files
committed
build every push; get version from git
1 parent e440fc3 commit 74e8d2e

File tree

2 files changed

+109
-42
lines changed

2 files changed

+109
-42
lines changed
Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
11
name: Build & Release
22

33
on:
4+
push:
5+
branches: [ "**" ]
46
workflow_dispatch:
7+
inputs:
8+
release_type:
9+
description: 'Draft a release for this build'
10+
required: false
11+
type: choice
12+
options: ['', 'MAJOR', 'MINOR', 'MICRO']
13+
14+
permissions:
15+
contents: write
516

617
jobs:
718
build:
819
runs-on: ubuntu-latest
920
container: devkitpro/devkita64:latest
21+
env:
22+
RELEASE_TYPE: ${{ inputs.release_type }}
23+
outputs:
24+
version_tag: ${{ steps.extract_version.outputs.tag_name }}
1025

1126
steps:
1227
- name: Checkout code
1328
uses: actions/checkout@v4
14-
29+
with:
30+
fetch-depth: 0
31+
filter: blob:none
32+
33+
- name: Build project
34+
run: |
35+
chown -R $(whoami):$(whoami) .
36+
make
37+
mkdir -p dist
38+
mv switch-time.nro dist
39+
1540
- name: Extract version from Makefile
1641
id: extract_version
42+
if: ${{ inputs.release_type != '' }}
1743
run: |
18-
APP_TITLE=$(grep -oP 'APP_TITLE\s*:=\s*\K.*' Makefile)
19-
VERSION_MAJOR=$(grep -oP 'VERSION_MAJOR\s*:=\s*\K.*' Makefile)
20-
VERSION_MINOR=$(grep -oP 'VERSION_MINOR\s*:=\s*\K.*' Makefile)
21-
VERSION_MICRO=$(grep -oP 'VERSION_MICRO\s*:=\s*\K.*' Makefile)
22-
APP_VERSION="v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}"
23-
echo "::set-output name=app_title::$APP_TITLE"
24-
echo "::set-output name=app_version::$APP_VERSION"
25-
echo "Extracted APP_TITLE: $APP_TITLE"
26-
echo "Extracted APP_VERSION: $APP_VERSION"
27-
28-
- name: Build project
29-
run: make
30-
31-
- name: Create Release
32-
id: create_release
33-
uses: actions/create-release@v1
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
VERSION=$(make version | xargs)
45+
echo "tag_name=$(echo $VERSION | sed 's/^[^0-9]*//')" >> $GITHUB_OUTPUT
46+
47+
- name: Upload artifacts
48+
uses: actions/upload-artifact@v4
3649
with:
37-
tag_name: ${{ steps.extract_version.outputs.app_version }}
38-
release_name: ${{ steps.extract_version.outputs.app_title }} ${{ steps.extract_version.outputs.app_version }}
39-
body: 'Automated release for ${{ steps.extract_version.outputs.app_version }}'
40-
draft: false
41-
prerelease: false
42-
43-
- name: Upload Release Asset
44-
uses: actions/upload-release-asset@v1
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
name: build-artifacts
51+
path: dist/
52+
53+
release:
54+
needs: build
55+
if: ${{ needs.build.outputs.version_tag != '' }}
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Download artifacts
59+
uses: actions/download-artifact@v4
4760
with:
48-
upload_url: ${{ steps.create_release.outputs.upload_url }}
49-
asset_path: ./switch-time.nro
50-
asset_name: switch-time.nro
51-
asset_content_type: application/octet-stream
61+
name: build-artifacts
62+
path: dist
63+
64+
- name: Draft release
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
run: |
68+
TAG="${{ needs.build.outputs.version_tag }}"
69+
gh release create "$TAG" dist/* \
70+
--repo ${{ github.repository }} \
71+
--target ${{ github.sha }} \
72+
--title "Release $TAG" \
73+
--generate-notes --draft

Makefile

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,62 @@ include $(DEVKITPRO)/libnx/switch_rules
3737
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
3838
# NACP building is skipped as well.
3939
#---------------------------------------------------------------------------------
40+
41+
GIT_DESCRIBE := $(patsubst v%,%,$(shell git describe --tags --always --dirty))
42+
43+
ifeq ($(findstring .,$(GIT_DESCRIBE)),)
44+
VERSION_MAJOR := 0
45+
VERSION_MINOR := 0
46+
VERSION_MICRO := 1
47+
else
48+
VERSION_MAJOR := $(word 1,$(subst ., ,$(GIT_DESCRIBE)))
49+
VERSION_MINOR := $(word 2,$(subst ., ,$(GIT_DESCRIBE)))
50+
VERSION_MICRO_FULL := $(word 3,$(subst ., ,$(GIT_DESCRIBE)))
51+
VERSION_MICRO := $(firstword $(subst -, ,$(VERSION_MICRO_FULL)))
52+
endif
53+
54+
increment = $(shell echo $$(($(1) + 1)))
55+
56+
ifeq ($(RELEASE_TYPE),MAJOR)
57+
VERSION_MAJOR := $(call increment,$(VERSION_MAJOR))
58+
VERSION_MINOR := 0
59+
VERSION_MICRO := 0
60+
endif
61+
62+
ifeq ($(RELEASE_TYPE),MINOR)
63+
VERSION_MINOR := $(call increment,$(VERSION_MINOR))
64+
VERSION_MICRO := 0
65+
endif
66+
67+
ifeq ($(RELEASE_TYPE),MICRO)
68+
VERSION_MICRO := $(call increment,$(VERSION_MICRO))
69+
endif
70+
71+
GITREV := $(shell git rev-parse --short HEAD)
72+
IS_DIRTY := $(findstring dirty,$(GIT_DESCRIBE))
73+
74+
VERSION_SUFFIX := -$(GITREV)
75+
ifneq ($(RELEASE_TYPE),)
76+
VERSION_SUFFIX :=
77+
else ifneq ($(GITHUB_ACTIONS),)
78+
VERSION_SUFFIX := c-$(GITREV)
79+
else ifneq ($(IS_DIRTY),)
80+
VERSION_SUFFIX := u-$(GITREV)
81+
else
82+
VERSION_SUFFIX := w-$(GITREV)
83+
endif
84+
85+
APP_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_MICRO)$(VERSION_SUFFIX)
86+
APP_TITLE := SwitchTime
87+
APP_AUTHOR := 3096, thedax, ZHDreamer, cytraen, vonhabsbourg, izenn, gzk_47
88+
4089
TARGET := switch-time
4190
BUILD := build
4291
SOURCES := source
4392
DATA := data
4493
INCLUDES := include
4594
#ROMFS := romfs
4695

47-
VERSION_MAJOR := 0
48-
VERSION_MINOR := 1
49-
VERSION_MICRO := 6
50-
51-
APP_TITLE := SwitchTime
52-
APP_AUTHOR := 3096, thedax, ZHDreamer, cytraen, vonhabsbourg, izenn, gzk_47
53-
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
54-
5596
#---------------------------------------------------------------------------------
5697
# options for code generation
5798
#---------------------------------------------------------------------------------
@@ -163,7 +204,7 @@ ifneq ($(ROMFS),)
163204
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
164205
endif
165206

166-
.PHONY: $(BUILD) clean all
207+
.PHONY: $(BUILD) version clean all
167208

168209
#---------------------------------------------------------------------------------
169210
all: $(BUILD)
@@ -182,6 +223,10 @@ else
182223
endif
183224

184225

226+
#---------------------------------------------------------------------------------
227+
version:
228+
@echo $(APP_VERSION)
229+
185230
#---------------------------------------------------------------------------------
186231
else
187232
.PHONY: all

0 commit comments

Comments
 (0)