|
| 1 | +name: Build and Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [main] |
| 5 | + pull_request: |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Release version (e.g., v1.0.0) - leave empty to auto-increment" |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + increment: |
| 14 | + description: "How to increment version if not specified" |
| 15 | + required: false |
| 16 | + default: "minor" |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - patch |
| 20 | + - minor |
| 21 | + - major |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - arch: "x86_64-linux" |
| 28 | + os: ubuntu-latest |
| 29 | + - arch: "aarch64-linux" |
| 30 | + os: ubuntu-24.04-arm |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 |
| 34 | + - uses: cachix/install-nix-action@c202056c6d0293bbc1c45caaa531f8f918914e53 # v31 |
| 35 | + - name: Building tarball for ${{ matrix.arch }} |
| 36 | + run: nix build |
| 37 | + - name: Uploading artifacts |
| 38 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 39 | + with: |
| 40 | + name: nixos-system-${{ matrix.arch }}.tar.xz |
| 41 | + path: result/tarball/nixos-system-${{ matrix.arch }}.tar.xz |
| 42 | + release: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + if: github.event_name == 'workflow_dispatch' |
| 45 | + needs: build |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + - name: Determine new version |
| 53 | + id: version |
| 54 | + run: | |
| 55 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 56 | + CLEAN_VERSION=${LATEST_TAG#v} |
| 57 | + if [[ -n "${{ github.event.inputs.version }}" ]]; then |
| 58 | + VERSION="${{ github.event.inputs.version }}" |
| 59 | + # Strip 'v' prefix if present, then add it back consistently |
| 60 | + CLEAN_VERSION=${INPUT_VERSION#v} |
| 61 | + VERSION="v$CLEAN_VERSION" |
| 62 | + echo "Using provided version: $VERSION" |
| 63 | + else |
| 64 | + # Ensure we have a full semver (pad with .0 if needed) |
| 65 | + case $(echo "$CLEAN_VERSION" | tr '.' '\n' | wc -l) in |
| 66 | + 1) CLEAN_VERSION="$CLEAN_VERSION.0.0" ;; |
| 67 | + 2) CLEAN_VERSION="$CLEAN_VERSION.0" ;; |
| 68 | + esac |
| 69 | + npm install -g semver |
| 70 | + NEW_VERSION=$(semver -i ${{ github.event.inputs.increment || 'minor' }} $CLEAN_VERSION) |
| 71 | + VERSION="v$NEW_VERSION" |
| 72 | + echo "Auto-incremented from $LATEST_TAG to: $VERSION" |
| 73 | + fi |
| 74 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 75 | + echo "prev_version=${LATEST_TAG}" >> $GITHUB_OUTPUT |
| 76 | + - name: Update README |
| 77 | + run: | |
| 78 | + sed -i 's/${{ steps.version.outputs.prev_version }}/${{ steps.version.outputs.version }}/g' README.md |
| 79 | +
|
| 80 | + git config --local user.name "github-actions[bot]" |
| 81 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 82 | + git add README.md |
| 83 | + git diff --staged --quiet || git commit -m "update README.md" |
| 84 | + git push |
| 85 | + - name: Create tag |
| 86 | + run: | |
| 87 | + git tag ${{ steps.version.outputs.version }} |
| 88 | + git push origin ${{ steps.version.outputs.version }} |
| 89 | + - name: Download artifacts |
| 90 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 |
| 91 | + with: |
| 92 | + path: artifacts/ |
| 93 | + - name: Create release |
| 94 | + run: | |
| 95 | + gh release create ${{ steps.version.outputs.version }} \ |
| 96 | + --title "Release ${{ steps.version.outputs.version }}" \ |
| 97 | + --notes "Release ${{ steps.version.outputs.version }}" \ |
| 98 | + --latest \ |
| 99 | + artifacts/*/nixos-system-*.tar.xz |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
0 commit comments