|
1 | 1 | name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - 'v*' |
| 4 | + workflow_run: |
| 5 | + workflows: ["Auto Tag"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + tag: |
| 11 | + description: 'Tag to release (e.g., v0.7.14)' |
| 12 | + required: true |
| 13 | + type: string |
7 | 14 |
|
8 | 15 | jobs: |
| 16 | + check-tag: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} |
| 19 | + outputs: |
| 20 | + tag: ${{ steps.get-tag.outputs.tag }} |
| 21 | + should_release: ${{ steps.get-tag.outputs.should_release }} |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Get tag |
| 30 | + id: get-tag |
| 31 | + run: | |
| 32 | + # Use input tag for manual dispatch, otherwise detect latest |
| 33 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 34 | + TAG="${{ inputs.tag }}" |
| 35 | + else |
| 36 | + TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 37 | + fi |
| 38 | +
|
| 39 | + if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 40 | + # Check if release already exists |
| 41 | + if gh release view "$TAG" &>/dev/null; then |
| 42 | + echo "Release $TAG already exists, skipping" |
| 43 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 46 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 47 | + echo "Will create release for $TAG" |
| 48 | + fi |
| 49 | + else |
| 50 | + echo "No valid semver tag found: $TAG" |
| 51 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
9 | 56 | build: |
| 57 | + needs: check-tag |
| 58 | + if: ${{ needs.check-tag.outputs.should_release == 'true' }} |
10 | 59 | strategy: |
11 | 60 | matrix: |
12 | 61 | include: |
|
22 | 71 | steps: |
23 | 72 | - name: Checkout repository |
24 | 73 | uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + ref: ${{ needs.check-tag.outputs.tag }} |
25 | 76 |
|
26 | 77 | - name: Setup Node.js |
27 | 78 | uses: actions/setup-node@v4 |
|
51 | 102 | if-no-files-found: error |
52 | 103 |
|
53 | 104 | release: |
54 | | - needs: build |
| 105 | + needs: [check-tag, build] |
55 | 106 | runs-on: ubuntu-latest |
56 | 107 | permissions: |
57 | 108 | contents: write |
|
73 | 124 | env: |
74 | 125 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
75 | 126 | run: | |
76 | | - gh release create ${{ github.ref_name }} \ |
| 127 | + gh release create ${{ needs.check-tag.outputs.tag }} \ |
77 | 128 | --generate-notes \ |
78 | 129 | artifacts/**/* |
0 commit comments