|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Get project information |
| 18 | + id: project_info |
| 19 | + run: | |
| 20 | + PROJECT_ID=$(jq -r '.id' manifest.json) |
| 21 | + VERSION=$(jq -r '.version' manifest.json) |
| 22 | + # Extract version from tag (removing the 'v' prefix if present) |
| 23 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 24 | + echo "project_id=$PROJECT_ID" >> $GITHUB_OUTPUT |
| 25 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 26 | + echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT |
| 27 | + |
| 28 | + - name: Check version match |
| 29 | + run: | |
| 30 | + # Compare the manifest version with the tag version (without 'v' prefix) |
| 31 | + if [ "${{ steps.project_info.outputs.version }}" != "${{ steps.project_info.outputs.tag_version }}" ]; then |
| 32 | + echo "::error::Version mismatch! Tag version v${{ steps.project_info.outputs.tag_version }} doesn't match manifest.json version ${{ steps.project_info.outputs.version }}" |
| 33 | + echo "Please update the version in manifest.json to match your tag or use the correct tag version" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + |
| 37 | + - name: Check for existing release |
| 38 | + id: check_release |
| 39 | + run: | |
| 40 | + RELEASE_EXISTS=$(gh release view "v${{ steps.project_info.outputs.version }}" --json id 2>/dev/null || echo "") |
| 41 | + if [ ! -z "$RELEASE_EXISTS" ]; then |
| 42 | + echo "::error::A release with version v${{ steps.project_info.outputs.version }} already exists!" |
| 43 | + echo "Please update the version in manifest.json before creating a new release" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Setup Node.js |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '20' |
| 51 | + cache: 'yarn' |
| 52 | + |
| 53 | + - name: Install dependencies |
| 54 | + run: yarn install --frozen-lockfile |
| 55 | + |
| 56 | + - name: Build |
| 57 | + run: yarn build |
| 58 | + |
| 59 | + - name: Create zip archive |
| 60 | + id: create_zip |
| 61 | + run: | |
| 62 | + ZIP_NAME="${{ steps.project_info.outputs.project_id }}-${{ steps.project_info.outputs.version }}.zip" |
| 63 | + zip -r "$ZIP_NAME" dist/ manifest.json LICENSE README.md |
| 64 | + echo "zip_name=$ZIP_NAME" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Extract changelog |
| 67 | + id: changelog |
| 68 | + run: | |
| 69 | + VERSION="${{ steps.project_info.outputs.version }}" |
| 70 | + if [ -f CHANGELOG.md ]; then |
| 71 | + # Extract section for current version if possible |
| 72 | + CHANGELOG=$(awk -v ver="## v$VERSION" 'BEGIN{flag=0} $0~ver{flag=1; next} /^## /{if(flag==1) exit} flag{print}' CHANGELOG.md) |
| 73 | + if [ -z "$CHANGELOG" ]; then |
| 74 | + CHANGELOG="Please add changelog details here." |
| 75 | + fi |
| 76 | + else |
| 77 | + CHANGELOG="Please add changelog details here." |
| 78 | + fi |
| 79 | + echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT |
| 80 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 81 | + echo "EOF" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + - name: Create GitHub Release |
| 84 | + uses: softprops/action-gh-release@v1 |
| 85 | + with: |
| 86 | + draft: true |
| 87 | + name: "Release v${{ steps.project_info.outputs.version }}" |
| 88 | + body: | |
| 89 | + # Release v${{ steps.project_info.outputs.version }} |
| 90 | + ${{ steps.changelog.outputs.CHANGELOG }} |
| 91 | + files: ${{ steps.create_zip.outputs.zip_name }} |
0 commit comments