Fix CI tag update by using GitHub API #155
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: [push, pull_request] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| mock-server: | |
| image: swaggerapi/petstore | |
| ports: | |
| - 8080:8080 | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Build with Maven | |
| run: mvn clean install | |
| - name: Test Generated Petstore Clients | |
| run: | | |
| curl -sL "https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml" > petstore_oas3.yaml | |
| curl -sL "https://petstore.swagger.io/v2/swagger.json" > petstore.json | |
| python3 scripts/test_petstore.py v2 petstore.json | |
| python3 scripts/test_petstore.py v3 petstore_oas3.yaml | |
| - name: Test Generated Petstore Servers | |
| run: | | |
| python3 scripts/test_generated_server.py v2 petstore.json | |
| python3 scripts/test_generated_server.py v3 petstore_oas3.yaml | |
| release: | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Build Standard JAR | |
| run: mvn clean package -DskipTests | |
| - name: Install Binaryen | |
| run: | | |
| curl -L https://github.com/WebAssembly/binaryen/releases/download/version_129/binaryen-version_129-x86_64-linux.tar.gz -o binaryen.tar.gz | |
| tar -xzf binaryen.tar.gz | |
| echo "$PWD/binaryen-version_129/bin" >> $GITHUB_PATH | |
| - name: Generate WASM Binary | |
| run: | | |
| python3 build_wasm.py | |
| - name: Verify WASM File Exists | |
| run: | | |
| if [ ! -f target/wasm/cdd-java.wasm ]; then | |
| echo "WASM file not found!" | |
| exit 1 | |
| fi | |
| - name: Build JS Wrapper & NPM Package | |
| run: | | |
| cd package | |
| npm install | |
| npm run build | |
| cp ../target/wasm/cdd-java.js ./dist/cdd-java.js | |
| cp ../target/wasm/cdd-java.wasm ./dist/cdd-java.wasm | |
| # - name: Publish NPM Package | |
| # run: | | |
| # cd package | |
| # # Update version based on tag | |
| # VERSION=${GITHUB_REF#refs/tags/} | |
| # VERSION=${VERSION#v} | |
| # # If tag is 'latest', maybe we don't want to fail npm version. We could skip it or handle it. | |
| # if [ "$VERSION" != "latest" ]; then | |
| # npm version $VERSION --no-git-tag-version | |
| # fi | |
| # npm publish --access public || echo "Publishing skipped or failed" | |
| # env: | |
| # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Rename and Checksum | |
| run: | | |
| cp target/wasm/cdd-java.wasm ./cdd-java.wasm | |
| cp target/wasm/cdd-java.js ./cdd-java.js | |
| sha256sum cdd-java.wasm > cdd-java.wasm.sha256 | |
| - name: Release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| files: | | |
| cdd-java.wasm | |
| cdd-java.js | |
| cdd-java.wasm.sha256 | |
| body: "WasmGC binary for cdd-java compiled via GraalVM Native Image 25 EA, bundled with JS Wrapper." | |
| draft: false | |
| prerelease: false | |
| - name: Update latest tag | |
| if: startsWith(github.ref, 'refs/tags/v') && github.ref != 'refs/tags/latest' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if ! gh api --method PATCH -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/git/refs/tags/latest -f sha=${{ github.sha }} -F force=true; then | |
| gh api --method POST -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/git/refs -f ref="refs/tags/latest" -f sha=${{ github.sha }} | |
| fi | |
| - name: Release to latest tag | |
| if: startsWith(github.ref, 'refs/tags/v') && github.ref != 'refs/tags/latest' | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: latest | |
| files: | | |
| cdd-java.wasm | |
| cdd-java.js | |
| cdd-java.wasm.sha256 | |
| body: "Latest WasmGC binary automatically updated from ${{ github.ref_name }}" | |
| draft: false | |
| prerelease: false | |
| make_latest: true |