Skip to content

Commit f63ab67

Browse files
committedFeb 1, 2025··
ci: generate api version
1 parent 79de273 commit f63ab67

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
 

‎.github/workflows/deploy-preview.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,27 @@ jobs:
4949
- name: test
5050
run: pnpm run test
5151

52+
- name: generate api version
53+
id: api-version
54+
env:
55+
HEAD_REF: ${{ github.head_ref }}
56+
REF_NAME: ${{ github.ref_name }}
57+
run: |
58+
BRANCH_NAME="${HEAD_REF:-$REF_NAME}"
59+
60+
# replace forward slashes and special characters with hyphens
61+
CLEAN_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
62+
63+
# get short SHA (first 7 characters)
64+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
65+
66+
# combine
67+
echo "version=$CLEAN_BRANCH-$SHORT_SHA" >> "$GITHUB_OUTPUT"
68+
5269
- name: deploy
5370
if: ${{ github.event.inputs.dry-run != 'true' }}
5471
env:
55-
API_VERSION: ${{ github.sha }}
72+
API_VERSION: ${{ steps.api-version.outputs.version }}
5673
uses: cloudflare/wrangler-action@6d58852c35a27e6034745c5d0bc373d739014f7f # v3.13.0
5774
with:
5875
apiToken: ${{ secrets.CF_API_TOKEN }}

‎.github/workflows/deploy.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,27 @@ jobs:
4848
- name: test
4949
run: pnpm run test
5050

51+
- name: generate api version
52+
id: api-version
53+
env:
54+
HEAD_REF: ${{ github.head_ref }}
55+
REF_NAME: ${{ github.ref_name }}
56+
run: |
57+
BRANCH_NAME="${HEAD_REF:-$REF_NAME}"
58+
59+
# replace forward slashes and special characters with hyphens
60+
CLEAN_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
61+
62+
# get short SHA (first 7 characters)
63+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
64+
65+
# combine
66+
echo "version=$CLEAN_BRANCH-$SHORT_SHA" >> "$GITHUB_OUTPUT"
67+
5168
- name: deploy
5269
if: ${{ github.event.inputs.dry-run != 'true' }}
5370
env:
54-
API_VERSION: ${{ github.sha }}
71+
API_VERSION: ${{ steps.api-version.outputs.version }}
5572
uses: cloudflare/wrangler-action@6d58852c35a27e6034745c5d0bc373d739014f7f # v3.13.0
5673
with:
5774
apiToken: ${{ secrets.CF_API_TOKEN }}

0 commit comments

Comments
 (0)
Please sign in to comment.