Your progression
Gm-E[SUP]b[/SUP]-Cm-D
Identify the notes in the chord
Gm ~ G-B[SUP]b[/SUP]-D
E[SUP]b[/SUP] ~ E[SUP]b[/SUP]-G-B[SUP]b[/SUP]
Cm ~ C-E[SUP]b[/SUP]-G
D ~ D-F[SUP]#[/SUP]-A
Take those notes and arrange them end to end
G-B[SUP]b[/SUP]-D-E[SUP]b[/SUP]-G-B[SUP]b[/SUP]-C-E[SUP]b[/SUP]-G-D-F[SUP]#[/SUP]-A
Eliminate duplicates
G-B[SUP]b[/SUP]-D-E[SUP]b[/SUP]-C-F[SUP]#[/SUP]-A
Now arrange alphabetically
Notes | A | | B[SUP]b[/SUP] | | C | | D | | E[SUP]b[/SUP] | | F[SUP]#[/SUP] | | G | | A |
Size | | S | | T | | T | | S | | T[SUP][SUP]1[/SUP]/[SUB]2[/SUB][/SUP] | | S | | T | |
Now rotate until you create a recognisable scale or mode
major ~
TTSTTTS
natural minor ~
TSTTSTTT
harmonic minor ~
TSTTSTT[SUP][SUP]1[/SUP]/[SUB]2[/SUB][/SUP]S
melodic minor ~
TSTTTTTS
G-A-B[SUP]b[/SUP]-C-D-E[SUP]b[/SUP]-F[SUP]#[/SUP]-G ~
TSTTSTT[SUP][SUP]1[/SUP]/[SUB]2[/SUB][/SUP]S
Based on this and a quick harmonic analysis
i-[SUP]b[/SUP]VI-iv-V
this is in G harmonic minor
your melody would therefore use either
G natural minor
G-A-B[SUP]b[/SUP]-C-D-E[SUP]b[/SUP]-F-G
or
G melodic minor
G-A-B[SUP]b[/SUP]-C-D-E-F[SUP]#[/SUP]-G - going up
G-A-B[SUP]b[/SUP]-C-D-E[SUP]b[/SUP]-F-G - going down.