build: implement versioning system #136
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| workflow_dispatch: | |
| env: | |
| MODULE_NAME: 'KPatch-Next-Module' | |
| GH_TOKEN: ${{ github.token }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.set_vars.outputs.version }} | |
| check_tag: ${{ steps.check_tag.outputs.need_release }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 1 | |
| - name: Load versions from version.properties | |
| run: | | |
| grep -v '^#' version.properties | sed -e 's/ *= */=/g' -e 's/"//g' >> $GITHUB_ENV | |
| - name: download kpatch-next binaries | |
| run: | | |
| mkdir -p module/bin | |
| TAG="${{ env['kpatch-next'] }}" | |
| ARGS=("-R" "KernelSU-Next/KPatch-Next" "-p" "kpatch-android" "-p" "kptools-android" "-p" "kpimg-linux" "-D" "module/bin") | |
| if [ "$TAG" != "latest" ]; then | |
| gh release download "$TAG" "${ARGS[@]}" | |
| else | |
| gh release download "${ARGS[@]}" | |
| fi | |
| mv module/bin/kpatch-android module/bin/kpatch | |
| mv module/bin/kptools-android module/bin/kptools | |
| mv module/bin/kpimg-linux module/bin/kpimg | |
| - name: Download magiskboot binary | |
| run: | | |
| TAG="${{ env.magiskboot }}" | |
| ARGS=("-R" "topjohnwu/Magisk" "-p" "Magisk*.apk" "-O" "magisk.apk") | |
| if [ "$TAG" != "latest" ]; then | |
| gh release download "$TAG" "${ARGS[@]}" | |
| else | |
| gh release download "${ARGS[@]}" | |
| fi | |
| unzip -p magisk.apk 'lib/arm64-v8a/libmagiskboot.so' > module/bin/magiskboot | |
| rm magisk.apk | |
| - name: build webroot | |
| run: | | |
| cd webui | |
| npm ci | |
| npm run build | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ${{ env.MODULE_NAME }}-${{ github.run_number }} | |
| path: 'module' | |
| - name: Check if valid to release | |
| id: check_tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "need_release=false" >> $GITHUB_OUTPUT | |
| else | |
| git fetch --tags | |
| VERSION="$(jq -r .version update.json)" | |
| if [ -z "$VERSION" ]; then | |
| echo "need_release=false" >> $GITHUB_OUTPUT | |
| elif git tag | grep -qx "^${VERSION}"; then | |
| echo "need_release=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "need_release=true" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: needs.release.outputs.check_tag == 'true' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 2 | |
| - name: Download artifact | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: ${{ env.MODULE_NAME }}-${{ github.run_number }} | |
| path: ${{ env.MODULE_NAME }} | |
| - name: Zip for release | |
| run: cd ${{ env.MODULE_NAME }} && zip -r ../${{ env.MODULE_NAME }}.zip . | |
| - name: Generate changelog | |
| run: | | |
| CHANGELOG_RAW=$(git diff HEAD^ HEAD -- "CHANGELOG.md" | grep '^+[^+]' | sed 's/^+//') | |
| { | |
| echo "CHANGELOG<<EOF" | |
| echo -e "${CHANGELOG_RAW}" | |
| echo "EOF" | |
| } >> $GITHUB_ENV | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.release.outputs.version }} | |
| name: ${{ needs.release.outputs.version }} | |
| body: ${{ env.CHANGELOG }} | |
| files: ${{ env.MODULE_NAME }}.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |