|
14 | 14 | jobs: |
15 | 15 | build-and-release: |
16 | 16 | runs-on: ubuntu-latest |
17 | | - |
| 17 | + # expose the release upload_url so downstream jobs can use it |
| 18 | + outputs: |
| 19 | + upload_url: ${{ steps.get_release.outputs.upload_url }} |
| 20 | + |
18 | 21 | steps: |
19 | 22 | - name: Checkout |
20 | 23 | uses: actions/checkout@v4 |
|
39 | 42 | - name: Package |
40 | 43 | run: npm run package |
41 | 44 |
|
| 45 | + - name: Check if release exists |
| 46 | + id: check_release |
| 47 | + env: |
| 48 | + TAG: ${{ github.ref_name || github.event.inputs.version }} |
| 49 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + run: | |
| 51 | + echo "Checking for release $TAG" |
| 52 | + resp=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \ |
| 53 | + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/$TAG") |
| 54 | + if echo "$resp" | grep -q '"message": "Not Found"'; then |
| 55 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 56 | + else |
| 57 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | +
|
42 | 60 | - name: Create Release |
| 61 | + id: create_release |
| 62 | + if: steps.check_release.outputs.exists == 'false' |
43 | 63 | uses: actions/create-release@v1 |
44 | 64 | env: |
45 | 65 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
@@ -67,12 +87,32 @@ jobs: |
67 | 87 |
|
68 | 88 | - name: Update major version tag |
69 | 89 | run: | |
| 90 | + # Accept either "v1.2.3" or "1.2.3" and always push a "v<MAJOR>" tag (e.g. v1) |
70 | 91 | VERSION=${{ github.ref_name || github.event.inputs.version }} |
71 | | - MAJOR_VERSION=$(echo $VERSION | cut -d. -f1) |
| 92 | + STRIPPED=${VERSION#v} |
| 93 | + MAJOR_NUMBER=$(echo "$STRIPPED" | cut -d. -f1) |
| 94 | + MAJOR_TAG="v${MAJOR_NUMBER}" |
72 | 95 | git config user.name github-actions |
73 | 96 | git config user.email github-actions@github.com |
74 | | - git tag -fa $MAJOR_VERSION -m "Update $MAJOR_VERSION tag" |
75 | | - git push origin $MAJOR_VERSION --force |
| 97 | + git tag -fa "$MAJOR_TAG" -m "Update $MAJOR_TAG tag" |
| 98 | + git push origin "$MAJOR_TAG" --force |
| 99 | +
|
| 100 | + - name: Get release info (upload_url) |
| 101 | + id: get_release |
| 102 | + env: |
| 103 | + TAG: ${{ github.ref_name || github.event.inputs.version }} |
| 104 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + run: | |
| 106 | + resp=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \ |
| 107 | + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/$TAG") |
| 108 | + # extract upload_url using Python to avoid depending on jq |
| 109 | + upload_url=$(python - <<'PY' |
| 110 | +import sys, json |
| 111 | +data = json.load(sys.stdin) |
| 112 | +print(data.get("upload_url", "")) |
| 113 | +PY |
| 114 | +<<<"$resp") |
| 115 | + echo "upload_url=$upload_url" >> $GITHUB_OUTPUT |
76 | 116 |
|
77 | 117 | marketplace: |
78 | 118 | needs: build-and-release |
|
88 | 128 | env: |
89 | 129 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
90 | 130 | with: |
91 | | - upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 131 | + upload_url: ${{ needs.build-and-release.outputs.upload_url }} |
92 | 132 | asset_path: ./action.yml |
93 | 133 | asset_name: action.yml |
94 | 134 | asset_content_type: text/yaml |
0 commit comments