Просмотр исходного кода

ci: trigger builds and releases on version tags

TheWildJames 6 месяцев назад
Родитель
Сommit
d9e87d4faf
1 измененных файлов с 66 добавлено и 19 удалено
  1. 66 19
      .github/workflows/main.yml

+ 66 - 19
.github/workflows/main.yml

@@ -47,6 +47,8 @@ on:
   push:
     branches:
       - main
+    tags:
+      - 'v*'
 
 jobs:
   fetch-commits:
@@ -66,7 +68,7 @@ jobs:
           ksu_commit: ${{ inputs.ksu_commit }}
 
   build-a12-5-10:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a12-5-10' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a12-5-10' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -79,7 +81,7 @@ jobs:
     secrets: inherit
 
   build-a13-5-10:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a13-5-10' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a13-5-10' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -92,7 +94,7 @@ jobs:
     secrets: inherit
 
   build-a13-5-15:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a13-5-15' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a13-5-15' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -105,7 +107,7 @@ jobs:
     secrets: inherit
 
   build-a14-5-15:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a14-5-15' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a14-5-15' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -118,7 +120,7 @@ jobs:
     secrets: inherit
 
   build-a14-6-1:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a14-6-1' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a14-6-1' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -131,7 +133,7 @@ jobs:
     secrets: inherit
 
   build-a15-6-6:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a15-6-6' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a15-6-6' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -144,7 +146,7 @@ jobs:
     secrets: inherit
 
   build-a16-6-12:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a16-6-12' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'a16-6-12' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -157,7 +159,7 @@ jobs:
     secrets: inherit
 
   build-lts:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'lts' || github.event_name == 'push' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'lts' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')) || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -170,7 +172,7 @@ jobs:
     secrets: inherit
 
   build-custom:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'custom' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'custom' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -183,7 +185,7 @@ jobs:
     secrets: inherit
 
   build-testing:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'testing' || github.event_name == 'push' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'testing' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')) || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -196,7 +198,7 @@ jobs:
     secrets: inherit
 
   build-bypass:
-    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'bypass' }}
+    if: ${{ inputs.kernel_build_version == 'all' || inputs.kernel_build_version == 'bypass' || startsWith(github.ref, 'refs/tags/v') }}
     needs: fetch-commits
     uses: ./.github/workflows/prepare.yml
     with:
@@ -280,7 +282,7 @@ jobs:
 
   release:
     runs-on: ubuntu-latest
-    if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_type != 'Actions' }}
+    if: ${{ (github.event_name == 'workflow_dispatch' && inputs.release_type != 'Actions') || startsWith(github.ref, 'refs/tags/v') }}
     permissions:
       contents: write
     needs:
@@ -294,6 +296,7 @@ jobs:
     - build-lts
     - build-custom
     - build-bypass
+    - rej
 
     env:
       GH_TOKEN: ${{ github.token }}
@@ -308,6 +311,9 @@ jobs:
 
         failed=0
         current_type="${{ inputs.kernel_build_version }}"
+        if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
+          current_type="all"
+        fi
 
         check_selected() {
           local target="$1"
@@ -355,10 +361,18 @@ jobs:
 
     - name: Checkout code
       uses: actions/checkout@v4
+      with:
+        fetch-depth: 0
+
+    - name: Ensure tag is from main
+      if: ${{ startsWith(github.ref, 'refs/tags/v') }}
+      run: |
+        git fetch origin main
+        git merge-base --is-ancestor "$GITHUB_SHA" "origin/main"
 
     - name: Generate New Tag
       id: tag
-      if: inputs.release_type != 'Actions'
+      if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_type != 'Actions' }}
       run: |
         LATEST_TAG=$(gh api repos/${{ github.repository }}/tags --jq '.[0].name' 2>/dev/null || echo "v0.0.0")
         if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then
@@ -420,14 +434,47 @@ jobs:
         -> https://github.com/sidex15/ksu_module_susfs
         EOF
 
+    - name: Resolve release tag
+      id: release_tag
+      run: |
+        if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
+          echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
+        else
+          echo "tag=${{ steps.tag.outputs.new_tag }}" >> "$GITHUB_OUTPUT"
+        fi
+
+    - name: Download AnyKernel3 Artifacts
+      uses: actions/download-artifact@v4
+      with:
+        path: ./downloaded-artifacts
+        pattern: '*-AnyKernel3'
+        merge-multiple: false
+
+    - name: Download AIO-REJ Artifact
+      uses: actions/download-artifact@v4
+      with:
+        path: ./downloaded-artifacts
+        pattern: 'AIO-REJ'
+        merge-multiple: true
+
+    - name: Package release zips
+      run: |
+        mkdir -p release-assets
+        for dir in ./downloaded-artifacts/*-AnyKernel3; do
+          [ -d "$dir" ] || continue
+          name=$(basename "$dir")
+          (cd "$dir" && zip -r -q -9 "../../release-assets/${name}.zip" .)
+        done
+        if [ -f "./downloaded-artifacts/AIO-REJ.zip" ]; then
+          cp "./downloaded-artifacts/AIO-REJ.zip" "./release-assets/AIO-REJ.zip"
+        fi
+
     - name: Create Release
       uses: softprops/action-gh-release@v1
       with:
-        tag_name: ${{ steps.tag.outputs.new_tag }}
-        name: ${{ steps.tag.outputs.new_tag }}
+        tag_name: ${{ steps.release_tag.outputs.tag }}
+        name: ${{ steps.release_tag.outputs.tag }}
         body_path: release_body.md
         draft: false
-        prerelease: ${{ inputs.release_type == 'Pre-Release' }}
-        files: |
-          AnyKernel3/**/*.zip
-          AIO-REJ.zip
+        prerelease: ${{ github.event_name == 'workflow_dispatch' && inputs.release_type == 'Pre-Release' }}
+        files: release-assets/*.zip