-
Notifications
You must be signed in to change notification settings - Fork 8
111 lines (93 loc) · 3.36 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (93 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Release
on:
workflow_run:
workflows: [Build]
types: [completed]
branches: [main]
permissions:
contents: write
actions: read
defaults:
run:
shell: bash
jobs:
check_commit:
name: Check Commit
runs-on: ubuntu-latest
outputs:
IS_RELEASE: ${{ steps.check_msg.outputs.IS_RELEASE }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Check latest commit message
id: check_msg
run: |
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B)
if echo "$LATEST_COMMIT_MSG" | grep -q "Release Prep v"; then
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
else
echo "IS_RELEASE=false" >> $GITHUB_OUTPUT
fi
release:
name: Release
needs: [check_commit]
if: ${{ needs.check_commit.outputs.IS_RELEASE == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha }}
- name: Extract version and find wasm artifact
id: find-artifact
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(git log -1 --pretty=%B | grep -oP 'Release Prep \Kv[0-9]+\.[0-9]+\.[0-9]+')
echo "version=$VERSION" >> $GITHUB_OUTPUT
ARTIFACT_NAME="wasm-${VERSION}"
RUN_ID=$(gh api "/repos/${{ github.repository }}/actions/artifacts?per_page=100" \
--jq "[.artifacts[] | select(.name == \"${ARTIFACT_NAME}\") | .workflow_run.id][0]")
if [ -z "$RUN_ID" ]; then
echo "Error: Could not find artifact ${ARTIFACT_NAME} in any workflow run" >&2
exit 1
fi
echo "Found ${ARTIFACT_NAME} in workflow run: $RUN_ID"
echo "run-id=$RUN_ID" >> $GITHUB_OUTPUT
- name: Download wasm
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ steps.find-artifact.outputs.run-id }}
name: wasm-${{ steps.find-artifact.outputs.version }}
- name: Calculate sha256
run: |
SHA256_HASH=$(sha256sum plugin.wasm | awk '{ print $1 }')
echo "SHA256_HASH=${SHA256_HASH}" >> $GITHUB_ENV
- name: Reconstruct release notes from PRs
id: notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
VERSION=${{ steps.find-artifact.outputs.version }}
PREVIOUS_TAG=$(git tag --sort=-v:refname | head -1)
NOTES_FILE=$(mktemp)
echo "notes-file=$NOTES_FILE" >> $GITHUB_OUTPUT
./scripts/generate-release-notes.sh \
"$PREVIOUS_TAG" "$VERSION" "$SHA256_HASH" \
--file "$NOTES_FILE"
- name: Create release and upload asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_TAG=${{ steps.find-artifact.outputs.version }}
mv plugin.wasm sqlc-gen-csharp.wasm
echo "Creating release ${NEW_TAG}..."
gh release create ${NEW_TAG} \
sqlc-gen-csharp.wasm \
--title "${NEW_TAG}" \
--notes-file "${{ steps.notes.outputs.notes-file }}"
echo "Release ${NEW_TAG} published successfully"