Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workflow for checking compatibility with postgres and postgis (MAPCO-6391) #35

Merged
merged 6 commits into from
Feb 4, 2025
156 changes: 156 additions & 0 deletions .github/workflows/postgis-check-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: postgis-check

on:
workflow_call:
inputs:
issue-number:
description: 'The issue-number of the slash command'
type: string
required: true
comment-creation-date:
description: 'The slash command creation date passed from the slash-command workflow'
type: string
required: true
versions:
description: 'Wanted postgis docker versions to check'
type: string
required: false
node-versions:
description: 'Node.js versions to check'
type: string
required: false

env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: postgres
DB_USERNAME: postgres
DB_PASSWORD: 1234
DEFAULT_VERSIONS: 12-2.5,13-3.3,14-3.3,14-3.5,16-3.5,17-3.5
DEFAULT_NODE_VERSIONS: 20.x

jobs:
set_version_inputs_if_empty:
name: Sets input to default if empty
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.set_version_inputs_if_empty.outputs.VERSIONS }}
node_versions: ${{ steps.set_version_inputs_if_empty.outputs.NODE_VERSIONS }}
steps:
- id: set_version_inputs_if_empty
run: |
if [ -z "${{inputs.versions}}" ]; then
versions=${{env.DEFAULT_VERSIONS}}
else
versions=${{ inputs.versions }}
fi

if [ -z "${{inputs.node-versions}}" ]; then
node_versions=${{env.DEFAULT_NODE_VERSIONS}}
else
node_versions=${{ inputs.node-versions }}
fi

echo "VERSIONS=$versions" >> $GITHUB_OUTPUT
echo "NODE_VERSIONS=$node_versions" >> $GITHUB_OUTPUT

# Convert versions variable from comma delimited string to JSON
versions_to_json:
name: Convert versions input to JSON
needs: [set_version_inputs_if_empty]
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.convert-to-json.outputs.VERSIONS }}
steps:
- id: convert-to-json
run: |
versions=$(echo ${{ needs.set_version_inputs_if_empty.outputs.versions }} | jq -R -c 'split(",")')
echo "VERSIONS=$versions" >> $GITHUB_OUTPUT

# Convert node-versions variable from comma-delimited string to JSON
node_versions_to_json:
name: Convert node-versions input to JSON
needs: [set_version_inputs_if_empty]
runs-on: ubuntu-latest
outputs:
node_versions: ${{ steps.convert-to-json.outputs.NODE_VERSIONS }}
steps:
- id: convert-to-json
run: |
versions=$(echo ${{ needs.set_version_inputs_if_empty.outputs.node_versions }} | jq -R -c 'split(",")')
echo "NODE_VERSIONS=$versions" >> $GITHUB_OUTPUT

# Create a PR comment for the workflow's results
create_comment:
name: Create comment
runs-on: ubuntu-latest
steps:
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ inputs.issue-number }}
body: |
**${{ inputs.comment-creation-date }}**
Checking postgis compatability for latest commit

tests:
name: Run Tests
needs: [node_versions_to_json, versions_to_json, create_comment]
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node: ${{ fromJSON(needs.node_versions_to_json.outputs.node_versions) }}
postgres: ${{ fromJSON(needs.versions_to_json.outputs.versions) }}

services:
postgres:
image: postgis/postgis:${{matrix.postgres}}
env:
POSTGRES_DB: ${{ env.DB_NAME }}
POSTGRES_USER: ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install TS Project dependencies
run: npm ci

- name: Run integration tests
id: test
run: npm run test:integration

# Find our bot's comment
- name: Find Comment
uses: peter-evans/find-comment@v3
if: always()
id: fc
with:
issue-number: ${{ inputs.issue-number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ inputs.comment-creation-date }}

# If a comment exists, update it with the test result
- name: Update comment
if: always() && steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
${{ steps.test.outcome == 'success' && ':white_check_mark:' || ':x:' }} run for `postgis/postgis:${{matrix.postgres}}`
27 changes: 27 additions & 0 deletions .github/workflows/slash-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Slash Command Dispatch

on:
workflow_call:

jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
id: scd
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commands: |
postgis-check
dispatch-type: workflow
static-args: |
issue-number=${{ github.event.issue.number }}
comment-creation-date=${{ github.event.comment.created_at }}
- name: Edit comment with error message
if: steps.scd.outputs.error-message
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
body: |
> ${{ steps.scd.outputs.error-message }}