|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + tag: |
| 12 | + description: "Release tag. Leave empty to update latest." |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-windows: |
| 21 | + runs-on: windows-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Check out repository |
| 25 | + uses: actions/checkout@v5 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v6 |
| 29 | + with: |
| 30 | + python-version: "3.13" |
| 31 | + |
| 32 | + - name: Set up Node.js |
| 33 | + uses: actions/setup-node@v6 |
| 34 | + with: |
| 35 | + node-version: "24" |
| 36 | + |
| 37 | + - name: Enable pnpm |
| 38 | + shell: pwsh |
| 39 | + run: | |
| 40 | + corepack enable |
| 41 | + corepack prepare pnpm@10 --activate |
| 42 | +
|
| 43 | + - name: Install dependencies |
| 44 | + shell: pwsh |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install -e .[dev] |
| 48 | + pnpm install --frozen-lockfile |
| 49 | +
|
| 50 | + - name: Run tests |
| 51 | + shell: pwsh |
| 52 | + run: | |
| 53 | + python -m pytest tests -q |
| 54 | +
|
| 55 | + - name: Build Electron package |
| 56 | + shell: pwsh |
| 57 | + run: | |
| 58 | + pnpm run electron:pack |
| 59 | +
|
| 60 | + - name: Upload release artifact |
| 61 | + uses: actions/upload-artifact@v6 |
| 62 | + with: |
| 63 | + name: weekflow-windows-release |
| 64 | + path: | |
| 65 | + dist/WeekFlow-V*.zip |
| 66 | +
|
| 67 | + publish-release: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: |
| 70 | + - build-windows |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Check out repository |
| 74 | + uses: actions/checkout@v5 |
| 75 | + |
| 76 | + - name: Resolve release tag |
| 77 | + id: release |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + PACKAGE_VERSION="$(python -c 'import json; print(json.load(open("package.json", encoding="utf-8"))["version"])')" |
| 81 | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ inputs.tag }}" ]]; then |
| 82 | + TAG_NAME="${{ inputs.tag }}" |
| 83 | + elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 84 | + TAG_NAME="${GITHUB_REF_NAME}" |
| 85 | + else |
| 86 | + TAG_NAME="latest" |
| 87 | + fi |
| 88 | + TITLE="WeekFlow-V$PACKAGE_VERSION" |
| 89 | + echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" |
| 90 | + echo "title=$TITLE" >> "$GITHUB_OUTPUT" |
| 91 | +
|
| 92 | + - name: Download built artifacts |
| 93 | + uses: actions/download-artifact@v6 |
| 94 | + with: |
| 95 | + path: release-assets |
| 96 | + merge-multiple: true |
| 97 | + |
| 98 | + - name: Publish GitHub release assets |
| 99 | + shell: bash |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ github.token }} |
| 102 | + GH_REPO: ${{ github.repository }} |
| 103 | + TAG_NAME: ${{ steps.release.outputs.tag_name }} |
| 104 | + TITLE: ${{ steps.release.outputs.title }} |
| 105 | + run: | |
| 106 | + ls -la release-assets |
| 107 | + if gh release view "$TAG_NAME" --repo "$GH_REPO" >/dev/null 2>&1; then |
| 108 | + gh release edit "$TAG_NAME" --repo "$GH_REPO" --title "$TITLE" |
| 109 | + if [[ "$TAG_NAME" == "latest" ]]; then |
| 110 | + gh api --method PATCH "repos/$GH_REPO/git/refs/tags/$TAG_NAME" -f sha="$GITHUB_SHA" -F force=true |
| 111 | + fi |
| 112 | + gh release view "$TAG_NAME" --repo "$GH_REPO" --json assets --jq '.assets[].name' | |
| 113 | + while read -r asset_name; do |
| 114 | + if [[ "$asset_name" == WeekFlow-* ]]; then |
| 115 | + gh release delete-asset "$TAG_NAME" "$asset_name" --repo "$GH_REPO" --yes |
| 116 | + fi |
| 117 | + done |
| 118 | + gh release upload "$TAG_NAME" release-assets/* --repo "$GH_REPO" --clobber |
| 119 | + else |
| 120 | + gh release create "$TAG_NAME" release-assets/* --repo "$GH_REPO" --title "$TITLE" --generate-notes --latest |
| 121 | + fi |
0 commit comments