|
14 | 14 | jobs: |
15 | 15 | build-and-release: |
16 | 16 | runs-on: ubuntu-latest |
17 | | - # expose the release upload_url so downstream jobs can use it |
18 | | - outputs: |
19 | | - upload_url: ${{ steps.get_release.outputs.upload_url }} |
20 | | - |
| 17 | + |
21 | 18 | steps: |
22 | 19 | - name: Checkout |
23 | 20 | uses: actions/checkout@v4 |
|
42 | 39 | - name: Package |
43 | 40 | run: npm run package |
44 | 41 |
|
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 | | -
|
60 | 42 | - name: Create Release |
61 | | - id: create_release |
62 | | - if: steps.check_release.outputs.exists == 'false' |
63 | 43 | uses: actions/create-release@v1 |
64 | 44 | env: |
65 | 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
@@ -87,32 +67,12 @@ jobs: |
87 | 67 |
|
88 | 68 | - name: Update major version tag |
89 | 69 | run: | |
90 | | - # Accept either "v1.2.3" or "1.2.3" and always push a "v<MAJOR>" tag (e.g. v1) |
91 | 70 | VERSION=${{ github.ref_name || github.event.inputs.version }} |
92 | | - STRIPPED=${VERSION#v} |
93 | | - MAJOR_NUMBER=$(echo "$STRIPPED" | cut -d. -f1) |
94 | | - MAJOR_TAG="v${MAJOR_NUMBER}" |
| 71 | + MAJOR_VERSION=$(echo $VERSION | cut -d. -f1) |
95 | 72 | git config user.name github-actions |
96 | 73 | git config user.email github-actions@github.com |
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 |
| 74 | + git tag -fa $MAJOR_VERSION -m "Update $MAJOR_VERSION tag" |
| 75 | + git push origin $MAJOR_VERSION --force |
116 | 76 |
|
117 | 77 | marketplace: |
118 | 78 | needs: build-and-release |
|
128 | 88 | env: |
129 | 89 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
130 | 90 | with: |
131 | | - upload_url: ${{ needs.build-and-release.outputs.upload_url }} |
| 91 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
132 | 92 | asset_path: ./action.yml |
133 | 93 | asset_name: action.yml |
134 | 94 | asset_content_type: text/yaml |
0 commit comments