|
| 1 | +# workflows/pgxn.yml |
| 2 | +# |
| 3 | +# Publish vchord (PGXN) |
| 4 | +# Build and publish the vchord extension to the PostgreSQL Extension Network (PGXN). This |
| 5 | +# workflow is gets triggered on a new release creation or manually via the GitHub UI. |
| 6 | + |
| 7 | +name: Publish vchord to PGXN |
| 8 | + |
| 9 | +on: |
| 10 | + release: |
| 11 | + types: [created] |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + tag: |
| 15 | + description: "tag name (semver without v-prefix)" |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + |
| 19 | +jobs: |
| 20 | + semver: |
| 21 | + runs-on: "ubuntu-latest" |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Semver |
| 25 | + id: semver |
| 26 | + uses: actions/github-script@v7 |
| 27 | + with: |
| 28 | + script: | |
| 29 | + const tag = "${{ github.event.inputs.tag }}" || "${{ github.event.release.tag_name }}"; |
| 30 | + console.log(`Tag: ${tag}`); |
| 31 | + const r = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; |
| 32 | + if (!r.test(tag)) { |
| 33 | + core.setFailed(`Action failed with an invalid semver.`); |
| 34 | + } |
| 35 | + core.setOutput('SEMVER', tag); |
| 36 | +
|
| 37 | + outputs: |
| 38 | + SEMVER: ${{ steps.semver.outputs.SEMVER }} |
| 39 | + |
| 40 | + publish: |
| 41 | + name: Publish to PGXN |
| 42 | + runs-on: ubuntu-latest |
| 43 | + needs: ["semver"] |
| 44 | + env: |
| 45 | + DISTNAME: vchord |
| 46 | + DISTVERSION: ${{ needs.semver.outputs.SEMVER }} |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Checkout Git Repository |
| 50 | + uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Bundle the Release |
| 53 | + run: | |
| 54 | + # Create a PGXN-compatible zip file. |
| 55 | + sed -e "s/@DISTVERSION@/${DISTVERSION}/g" META.json.in > META.json |
| 56 | + # Create the build directory |
| 57 | + mkdir -p ./build |
| 58 | + # Output the archive to ./build/ and use DISTNAME--DISTVERSION.zip |
| 59 | + git archive --format zip --prefix "${DISTNAME}-${DISTVERSION}/" --add-file META.json -o "./build/${DISTNAME}--${DISTVERSION}.zip" HEAD |
| 60 | + echo "Release bundle created: ./build/${DISTNAME}--${DISTVERSION}.zip" |
| 61 | +
|
| 62 | + - name: Release on PGXN |
| 63 | + env: |
| 64 | + PGXN_USERNAME: ${{ secrets.PGXN_USERNAME }} |
| 65 | + PGXN_PASSWORD: ${{ secrets.PGXN_PASSWORD }} |
| 66 | + run: | |
| 67 | + # DISTNAME and DISTVERSION are available from the job's env context |
| 68 | + ARCHIVE_PATH="./build/${DISTNAME}--${DISTVERSION}.zip" |
| 69 | + echo "Uploading ${ARCHIVE_PATH} to PGXN..." |
| 70 | + curl --fail -sS \ |
| 71 | + --user "${PGXN_USERNAME}:${PGXN_PASSWORD}" \ |
| 72 | + -F "submit=Release It!" \ |
| 73 | + -F "archive=@${ARCHIVE_PATH}" \ |
| 74 | + -H "X-Requested-With: XMLHttpRequest" \ |
| 75 | + https://manager.pgxn.org/upload |
0 commit comments