|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build and Upload Artifact |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + artifact_name: ${{ steps.rename_artifact.outputs.artifact_name }} |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '20' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: npm ci |
| 28 | + |
| 29 | + - name: Run build |
| 30 | + run: npm run package |
| 31 | + |
| 32 | + - name: Rename artifact |
| 33 | + id: rename_artifact |
| 34 | + run: | |
| 35 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 36 | + tagName=${GITHUB_REF#refs/tags/} |
| 37 | + echo "Renaming artifact to extension-$tagName.zip" |
| 38 | + mv extension.fplx extension-$tagName.zip |
| 39 | + echo "artifact_name=extension-$tagName" >> $GITHUB_OUTPUT |
| 40 | + echo "artifact_path=extension-$tagName.zip" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + commitHash=$(git rev-parse --short "$GITHUB_SHA") |
| 43 | + echo "Renaming artifact to extension-$commitHash.zip" |
| 44 | + mv extension.fplx extension-$commitHash.zip |
| 45 | + echo "artifact_name=extension-$commitHash" >> $GITHUB_OUTPUT |
| 46 | + echo "artifact_path=extension-$commitHash.zip" >> $GITHUB_OUTPUT |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Upload release artifact |
| 50 | + if: ${{ !env.ACT }} |
| 51 | + uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: ${{ steps.rename_artifact.outputs.artifact_name }} |
| 54 | + path: ${{ steps.rename_artifact.outputs.artifact_path }} |
| 55 | + |
| 56 | + release: |
| 57 | + name: Create Release |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: build |
| 60 | + if: startsWith(github.ref, 'refs/tags/v') |
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - uses: actions/download-artifact@v4 |
| 66 | + if: ${{ !env.ACT }} |
| 67 | + with: |
| 68 | + name: ${{ needs.build.outputs.artifact_name }} |
| 69 | + |
| 70 | + - name: Extract changelog entry |
| 71 | + id: changelog |
| 72 | + run: | |
| 73 | + tagName=${GITHUB_REF#refs/tags/} |
| 74 | + tagName=${tagName#v} |
| 75 | + awk "/## \\[${tagName}\\]/ {flag=1; next} /^## \\[/ {flag=0} flag {print}" CHANGELOG.md > extracted_changelog.md |
| 76 | + echo "Extracted changelog:" |
| 77 | + cat extracted_changelog.md |
| 78 | + echo "tagName=${tagName}" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + - name: Release |
| 81 | + if: ${{ !env.ACT }} |
| 82 | + uses: softprops/action-gh-release@v2 |
| 83 | + with: |
| 84 | + name: "Release ${{ steps.changelog.outputs.tagName }}" |
| 85 | + tag_name: "v${{ steps.changelog.outputs.tagName }}" |
| 86 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + body_path: extracted_changelog.md |
| 88 | + files: extension-*.zip |
0 commit comments