This would be simple if the friction didn't change direction
Indeed. So here is one way to deal with it. First, determine the initial velocity at t=0. E.g. let's just say v(0) is positive. Then instead of
$ma =sign(v) * mg*\mu - kx$
$ma =mg*\mu - kx$
Now, solve that equation, which should be pretty easy, and plot velocity versus time. You'll note that at some point, the velocity is no longer positive, and has changed to negative. Let's just call that time $t_1$. i.e. $v(t_1)=0$. So at that point, "stop" that solution, and write a new equation
$ma =-mg*\mu - kx$
this equation "starts" at time $t=t_1$ with initial conditions $v(t_1)=0$ and $x(t_1)$ determined from the ending position of the first solution. This equation should also be easy to solve. Continue the process, switching back and forth as necessary. At each point, you will also need to check if the spring force is enough to overcome the static friction. At some point it will not be, and then you stop. At the end, stitch together all of the partial solutions to each segment into one big piecewise solution.
Use numerical integration. E.g. apply Euler's method for solving differential equations. Over each time step, you can assume that the friction force acts in a constant direction. Assuming the time steps are small enough, you'll get about the same answer as above.